Merged.
authorballarin
Fri Dec 05 11:42:27 2008 +0100 (2008-12-05)
changeset 2899449f602ae24e5
parent 28993 829e684b02ef
parent 28992 c4ae153d78ab
child 28995 d59b8124f1f5
child 29004 a5a91f387791
child 29010 5cd646abf6bc
child 29018 17538bdef546
child 29676 cfa3378decf7
Merged.
src/HOL/Complex/Complex.thy
src/HOL/Complex/Complex_Main.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/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/Series.thy
src/HOL/Hyperreal/Taylor.thy
src/HOL/Hyperreal/Transcendental.thy
src/HOL/Library/Code_Message.thy
src/HOL/Library/GCD.thy
src/HOL/Library/Order_Relation.thy
src/HOL/Library/Parity.thy
src/HOL/Library/RType.thy
src/HOL/Library/Univ_Poly.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/float_arith.ML
src/HOL/Real/float_syntax.ML
src/HOL/Real/rat_arith.ML
src/HOL/Real/real_arith.ML
src/HOL/arith_data.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/Pure/Isar/expression.ML
src/Pure/Isar/new_locale.ML
src/Pure/Tools/quickcheck.ML
src/Pure/Tools/value.ML
     1.1 --- a/Admin/CHECKLIST	Fri Dec 05 11:26:07 2008 +0100
     1.2 +++ b/Admin/CHECKLIST	Fri Dec 05 11:42:27 2008 +0100
     1.3 @@ -16,18 +16,17 @@
     1.4  - check ANNOUNCE, README, INSTALL, NEWS, COPYRIGHT, CONTRIBUTORS, ~isabelle/website;
     1.5  
     1.6  - maintain Docs:
     1.7 -    Doc/Dirs
     1.8 -    Distribution/doc/Contents
     1.9 +    doc-src/Dirs
    1.10 +    doc/Contents
    1.11  
    1.12  - maintain Logics:
    1.13      Admin/makedist
    1.14 -    Distribution/build
    1.15 -    Distribution/lib/Tools/makeall
    1.16 -    Distribution/lib/html/index.html
    1.17 -    Doc/Logics/intro.tex
    1.18 -    Doc/Logics/logics.tex
    1.19 +    build
    1.20 +    lib/Tools/makeall
    1.21 +    lib/html/index.html
    1.22 +    doc-src/Logics/intro.tex
    1.23 +    doc-src/Logics/logics.tex
    1.24  
    1.25  - after release: 
    1.26      commit new ~isabelle/website/include/documentationdist.include.html to website SVN
    1.27  
    1.28 -$Id$
     2.1 --- a/Admin/build	Fri Dec 05 11:26:07 2008 +0100
     2.2 +++ b/Admin/build	Fri Dec 05 11:42:27 2008 +0100
     2.3 @@ -1,7 +1,5 @@
     2.4  #!/usr/bin/env bash
     2.5  #
     2.6 -# $Id$
     2.7 -#
     2.8  # Administrative build for Isabelle source distribution.
     2.9  
    2.10  ## global environment
    2.11 @@ -14,19 +12,8 @@
    2.12  
    2.13  ## directory layout
    2.14  
    2.15 -ISABELLE_DIR="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)"
    2.16 -
    2.17 -if [ -d "$ISABELLE_DIR/Distribution" ]; then
    2.18 -  ISABELLE_TOOL="$ISABELLE_DIR/Distribution/bin/isabelle"
    2.19 -  ISABELLE_LIB="$ISABELLE_DIR/Distribution/lib"
    2.20 -  ISABELLE_SRC="$ISABELLE_DIR"
    2.21 -  ISABELLE_DOC_SRC="$ISABELLE_DIR/Doc"
    2.22 -else
    2.23 -  ISABELLE_TOOL="$ISABELLE_DIR/bin/isabelle"
    2.24 -  ISABELLE_LIB="$ISABELLE_DIR/lib"
    2.25 -  ISABELLE_SRC="$ISABELLE_DIR/src"
    2.26 -  ISABELLE_DOC_SRC="$ISABELLE_DIR/doc-src"
    2.27 -fi
    2.28 +ISABELLE_HOME="$(cd "$(dirname "$0")"; cd "$(pwd -P)"; cd ..; pwd)"
    2.29 +ISABELLE_TOOL="$ISABELLE_HOME/bin/isabelle"
    2.30  
    2.31  
    2.32  ## diagnostics
    2.33 @@ -81,7 +68,7 @@
    2.34    echo "### Building graph browser ..."
    2.35    echo "###"
    2.36  
    2.37 -  cd "$ISABELLE_LIB/browser"
    2.38 +  cd "$ISABELLE_HOME/lib/browser"
    2.39    make clean all || fail "Failed to build graph browser!"
    2.40  }
    2.41  
    2.42 @@ -92,7 +79,7 @@
    2.43    echo "### Building documentation ..."
    2.44    echo "###"
    2.45  
    2.46 -  cd "$ISABELLE_DOC_SRC"
    2.47 +  cd "$ISABELLE_HOME/doc-src"
    2.48    for DOC in $(cat Dirs)
    2.49    do
    2.50      pushd "$DOC" >/dev/null
    2.51 @@ -111,12 +98,12 @@
    2.52  
    2.53    type -p scalac >/dev/null || fail "Scala compiler unavailable"
    2.54  
    2.55 -  pushd "$ISABELLE_SRC/Pure" >/dev/null
    2.56 +  pushd "$ISABELLE_HOME/src/Pure" >/dev/null
    2.57    "$ISABELLE_TOOL" make jar || fail "Failed to build Pure.jar!"
    2.58    popd >/dev/null
    2.59  
    2.60    if [ -d "$HOME/lib/jedit/current" ]; then
    2.61 -    pushd "$ISABELLE_LIB/jedit/plugin" >/dev/null
    2.62 +    pushd "$ISABELLE_HOME/lib/jedit/plugin" >/dev/null
    2.63      ./mk
    2.64      [ -f ../isabelle.jar ] || fail "Failed to build jEdit plugin!"
    2.65      popd >/dev/null
     3.1 --- a/Admin/isatest/isatest-makeall	Fri Dec 05 11:26:07 2008 +0100
     3.2 +++ b/Admin/isatest/isatest-makeall	Fri Dec 05 11:42:27 2008 +0100
     3.3 @@ -133,6 +133,11 @@
     3.4  
     3.5      echo ------------------- starting test --- `date` --- $HOSTNAME > $TESTLOG 2>&1
     3.6  
     3.7 +    if [ "${ISABELLE_HOME_USER:0:14}" == "/tmp/isabelle-" ]; then
     3.8 +        echo "--- cleaning up old $ISABELLE_HOME_USER"
     3.9 +        rm -rf $ISABELLE_HOME_USER
    3.10 +    fi
    3.11 +
    3.12      cat $SETTINGS >> $DISTPREFIX/Isabelle/etc/settings
    3.13      (ulimit -t $MAXTIME; cd $DIR; $NICE $TOOL >> $TESTLOG 2>&1)
    3.14  
     4.1 --- a/Admin/isatest/settings/sun-poly	Fri Dec 05 11:26:07 2008 +0100
     4.2 +++ b/Admin/isatest/settings/sun-poly	Fri Dec 05 11:42:27 2008 +0100
     4.3 @@ -6,7 +6,7 @@
     4.4    ML_HOME="$POLYML_HOME/$ML_PLATFORM"
     4.5    ML_OPTIONS="-H 1500"
     4.6  
     4.7 -ISABELLE_HOME_USER=~/isabelle-sun-poly
     4.8 +ISABELLE_HOME_USER=/tmp/isabelle-sun-poly
     4.9  
    4.10  # Where to look for isabelle tools (multiple dirs separated by ':').
    4.11  ISABELLE_TOOLS="$ISABELLE_HOME/lib/Tools"
     5.1 --- a/NEWS	Fri Dec 05 11:26:07 2008 +0100
     5.2 +++ b/NEWS	Fri Dec 05 11:42:27 2008 +0100
     5.3 @@ -55,9 +55,28 @@
     5.4  * Removed exotic 'token_translation' command.  INCOMPATIBILITY, use ML
     5.5  interface instead.
     5.6  
     5.7 +* There is a new lexical item "float" with syntax ["-"] digit+ "." digit+,
     5.8 +without spaces.
     5.9 +
    5.10  
    5.11  *** Pure ***
    5.12  
    5.13 +* Type Binding.T gradually replaces formerly used type bstring for names
    5.14 +to be bound.  Name space interface for declarations has been simplified:
    5.15 +
    5.16 +  NameSpace.declare: NameSpace.naming
    5.17 +    -> Binding.T -> NameSpace.T -> string * NameSpace.T
    5.18 +  NameSpace.bind: NameSpace.naming
    5.19 +    -> Binding.T * 'a -> 'a NameSpace.table -> string * 'a NameSpace.table
    5.20 +         (*exception Symtab.DUP*)
    5.21 +
    5.22 +See further modules src/Pure/General/binding.ML and
    5.23 +src/Pure/General/name_space.ML
    5.24 +
    5.25 +* Module moves in repository:
    5.26 +    src/Pure/Tools/value.ML ~> src/Tools/
    5.27 +    src/Pure/Tools/quickcheck.ML ~> src/Tools/
    5.28 +
    5.29  * Slightly more coherent Pure syntax, with updated documentation in
    5.30  isar-ref manual.  Removed locales meta_term_syntax and
    5.31  meta_conjunction_syntax: TERM and &&& (formerly &&) are now permanent,
    5.32 @@ -133,6 +152,50 @@
    5.33  
    5.34  *** HOL ***
    5.35  
    5.36 +* Made repository layout more coherent with logical
    5.37 +distribution structure:
    5.38 +
    5.39 +    src/HOL/Library/RType.thy ~> src/HOL/Typerep.thy
    5.40 +    src/HOL/Library/Code_Message.thy ~> src/HOL/
    5.41 +    src/HOL/Library/GCD.thy ~> src/HOL/
    5.42 +    src/HOL/Library/Order_Relation.thy ~> src/HOL/
    5.43 +    src/HOL/Library/Parity.thy ~> src/HOL/
    5.44 +    src/HOL/Library/Univ_Poly.thy ~> src/HOL/
    5.45 +    src/HOL/Real/ContNotDenum.thy ~> src/HOL/
    5.46 +    src/HOL/Real/Lubs.thy ~> src/HOL/
    5.47 +    src/HOL/Real/PReal.thy ~> src/HOL/
    5.48 +    src/HOL/Real/Rational.thy ~> src/HOL/
    5.49 +    src/HOL/Real/RComplete.thy ~> src/HOL/
    5.50 +    src/HOL/Real/RealDef.thy ~> src/HOL/
    5.51 +    src/HOL/Real/RealPow.thy ~> src/HOL/
    5.52 +    src/HOL/Real/Real.thy ~> src/HOL/
    5.53 +    src/HOL/Complex/Complex_Main.thy ~> src/HOL/
    5.54 +    src/HOL/Complex/Complex.thy ~> src/HOL/
    5.55 +    src/HOL/Complex/FrechetDeriv.thy ~> src/HOL/
    5.56 +    src/HOL/Hyperreal/Deriv.thy ~> src/HOL/
    5.57 +    src/HOL/Hyperreal/Fact.thy ~> src/HOL/
    5.58 +    src/HOL/Hyperreal/Integration.thy ~> src/HOL/
    5.59 +    src/HOL/Hyperreal/Lim.thy ~> src/HOL/
    5.60 +    src/HOL/Hyperreal/Ln.thy ~> src/HOL/
    5.61 +    src/HOL/Hyperreal/Log.thy ~> src/HOL/
    5.62 +    src/HOL/Hyperreal/MacLaurin.thy ~> src/HOL/
    5.63 +    src/HOL/Hyperreal/NthRoot.thy ~> src/HOL/
    5.64 +    src/HOL/Hyperreal/Series.thy ~> src/HOL/
    5.65 +    src/HOL/Hyperreal/Taylor.thy ~> src/HOL/
    5.66 +    src/HOL/Hyperreal/Transcendental.thy ~> src/HOL/
    5.67 +    src/HOL/Real/Float ~> src/HOL/Library/
    5.68 +
    5.69 +    src/HOL/arith_data.ML ~> src/HOL/Tools
    5.70 +    src/HOL/hologic.ML ~> src/HOL/Tools
    5.71 +    src/HOL/simpdata.ML ~> src/HOL/Tools
    5.72 +    src/HOL/int_arith1.ML ~> src/HOL/Tools/int_arith.ML
    5.73 +    src/HOL/int_factor_simprocs.ML ~> src/HOL/Tools
    5.74 +    src/HOL/nat_simprocs.ML ~> src/HOL/Tools
    5.75 +    src/HOL/Real/float_arith.ML ~> src/HOL/Tools
    5.76 +    src/HOL/Real/float_syntax.ML ~> src/HOL/Tools
    5.77 +    src/HOL/Real/rat_arith.ML ~> src/HOL/Tools
    5.78 +    src/HOL/Real/real_arith.ML ~> src/HOL/Tools
    5.79 +
    5.80  * If methods "eval" and "evaluation" encounter a structured proof state
    5.81  with !!/==>, only the conclusion is evaluated to True (if possible),
    5.82  avoiding strange error messages.
    5.83 @@ -221,6 +284,9 @@
    5.84  
    5.85  * HOL/Real/Rational: 'Fract k 0' now equals '0'.  INCOMPATIBILITY.
    5.86  
    5.87 +* The real numbers offer decimal input syntax: 12.34 is translated into
    5.88 +  1234/10^4. This translation is not reversed upon output.
    5.89 +
    5.90  * New ML antiquotation @{code}: takes constant as argument, generates
    5.91  corresponding code in background and inserts name of the corresponding
    5.92  resulting ML value/function/datatype constructor binding in place.
     6.1 --- a/doc-src/Makefile.in	Fri Dec 05 11:26:07 2008 +0100
     6.2 +++ b/doc-src/Makefile.in	Fri Dec 05 11:42:27 2008 +0100
     6.3 @@ -13,7 +13,7 @@
     6.4  SEDINDEX = ../sedindex
     6.5  FIXBOOKMARKS = perl -pi ../fixbookmarks.pl
     6.6  
     6.7 -DEFAULT_GARBAGE = *.aux *.log *.toc *.idx *.rai *.rao *.bbl *.ind *.ilg *.blg *.out
     6.8 +DEFAULT_GARBAGE = *.aux *.log *.toc *.idx *.rai *.rao *.bbl *.ind *.ilg *.blg *.out *.lof
     6.9  DEFAULT_OUTPUT = *.dvi *.pdf *.ps
    6.10  GARBAGE =
    6.11  OUTPUT =
     7.1 --- a/doc-src/TutorialI/Types/Numbers.thy	Fri Dec 05 11:26:07 2008 +0100
     7.2 +++ b/doc-src/TutorialI/Types/Numbers.thy	Fri Dec 05 11:42:27 2008 +0100
     7.3 @@ -1,4 +1,3 @@
     7.4 -(* ID:         $Id$ *)
     7.5  theory Numbers
     7.6  imports Complex_Main
     7.7  begin
     8.1 --- a/src/HOL/Arith_Tools.thy	Fri Dec 05 11:26:07 2008 +0100
     8.2 +++ b/src/HOL/Arith_Tools.thy	Fri Dec 05 11:42:27 2008 +0100
     8.3 @@ -11,8 +11,8 @@
     8.4  uses
     8.5    "~~/src/Provers/Arith/cancel_numeral_factor.ML"
     8.6    "~~/src/Provers/Arith/extract_common_term.ML"
     8.7 -  "int_factor_simprocs.ML"
     8.8 -  "nat_simprocs.ML"
     8.9 +  "Tools/int_factor_simprocs.ML"
    8.10 +  "Tools/nat_simprocs.ML"
    8.11    "Tools/Qelim/qelim.ML"
    8.12  begin
    8.13  
    17.1 --- a/src/HOL/Code_Eval.thy	Fri Dec 05 11:26:07 2008 +0100
    17.2 +++ b/src/HOL/Code_Eval.thy	Fri Dec 05 11:42:27 2008 +0100
    17.3 @@ -6,7 +6,7 @@
    17.4  header {* Term evaluation using the generic code generator *}
    17.5  
    17.6  theory Code_Eval
    17.7 -imports Plain "~~/src/HOL/Library/RType"
    17.8 +imports Plain Typerep
    17.9  begin
   17.10  
   17.11  subsection {* Term representation *}
   17.12 @@ -63,7 +63,7 @@
   17.13        thy
   17.14        |> TheoryTarget.instantiation ([tyco], vs, @{sort term_of})
   17.15        |> `(fn lthy => Syntax.check_term lthy eq)
   17.16 -      |-> (fn eq => Specification.definition (NONE, ((Name.binding (triv_name_of eq), []), eq)))
   17.17 +      |-> (fn eq => Specification.definition (NONE, ((Binding.name (triv_name_of eq), []), eq)))
   17.18        |> snd
   17.19        |> Class.prove_instantiation_instance (K (Class.intro_classes_tac []))
   17.20        |> LocalTheory.exit_global
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/src/HOL/Code_Message.thy	Fri Dec 05 11:42:27 2008 +0100
    18.3 @@ -0,0 +1,58 @@
    18.4 +(*  ID:         $Id$
    18.5 +    Author:     Florian Haftmann, TU Muenchen
    18.6 +*)
    18.7 +
    18.8 +header {* Monolithic strings (message strings) for code generation *}
    18.9 +
   18.10 +theory Code_Message
   18.11 +imports Plain "~~/src/HOL/List"
   18.12 +begin
   18.13 +
   18.14 +subsection {* Datatype of messages *}
   18.15 +
   18.16 +datatype message_string = STR string
   18.17 +
   18.18 +lemmas [code del] = message_string.recs message_string.cases
   18.19 +
   18.20 +lemma [code]: "size (s\<Colon>message_string) = 0"
   18.21 +  by (cases s) simp_all
   18.22 +
   18.23 +lemma [code]: "message_string_size (s\<Colon>message_string) = 0"
   18.24 +  by (cases s) simp_all
   18.25 +
   18.26 +subsection {* ML interface *}
   18.27 +
   18.28 +ML {*
   18.29 +structure Message_String =
   18.30 +struct
   18.31 +
   18.32 +fun mk s = @{term STR} $ HOLogic.mk_string s;
   18.33 +
   18.34 +end;
   18.35 +*}
   18.36 +
   18.37 +
   18.38 +subsection {* Code serialization *}
   18.39 +
   18.40 +code_type message_string
   18.41 +  (SML "string")
   18.42 +  (OCaml "string")
   18.43 +  (Haskell "String")
   18.44 +
   18.45 +setup {*
   18.46 +  fold (fn target => add_literal_message @{const_name STR} target)
   18.47 +    ["SML", "OCaml", "Haskell"]
   18.48 +*}
   18.49 +
   18.50 +code_reserved SML string
   18.51 +code_reserved OCaml string
   18.52 +
   18.53 +code_instance message_string :: eq
   18.54 +  (Haskell -)
   18.55 +
   18.56 +code_const "eq_class.eq \<Colon> message_string \<Rightarrow> message_string \<Rightarrow> bool"
   18.57 +  (SML "!((_ : string) = _)")
   18.58 +  (OCaml "!((_ : string) = _)")
   18.59 +  (Haskell infixl 4 "==")
   18.60 +
   18.61 +end
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/HOL/Complex.thy	Fri Dec 05 11:42:27 2008 +0100
    19.3 @@ -0,0 +1,718 @@
    19.4 +(*  Title:       Complex.thy
    19.5 +    Author:      Jacques D. Fleuriot
    19.6 +    Copyright:   2001 University of Edinburgh
    19.7 +    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
    19.8 +*)
    19.9 +
   19.10 +header {* Complex Numbers: Rectangular and Polar Representations *}
   19.11 +
   19.12 +theory Complex
   19.13 +imports Transcendental
   19.14 +begin
   19.15 +
   19.16 +datatype complex = Complex real real
   19.17 +
   19.18 +primrec
   19.19 +  Re :: "complex \<Rightarrow> real"
   19.20 +where
   19.21 +  Re: "Re (Complex x y) = x"
   19.22 +
   19.23 +primrec
   19.24 +  Im :: "complex \<Rightarrow> real"
   19.25 +where
   19.26 +  Im: "Im (Complex x y) = y"
   19.27 +
   19.28 +lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
   19.29 +  by (induct z) simp
   19.30 +
   19.31 +lemma complex_equality [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y"
   19.32 +  by (induct x, induct y) simp
   19.33 +
   19.34 +lemma expand_complex_eq: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y"
   19.35 +  by (induct x, induct y) simp
   19.36 +
   19.37 +lemmas complex_Re_Im_cancel_iff = expand_complex_eq
   19.38 +
   19.39 +
   19.40 +subsection {* Addition and Subtraction *}
   19.41 +
   19.42 +instantiation complex :: ab_group_add
   19.43 +begin
   19.44 +
   19.45 +definition
   19.46 +  complex_zero_def: "0 = Complex 0 0"
   19.47 +
   19.48 +definition
   19.49 +  complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)"
   19.50 +
   19.51 +definition
   19.52 +  complex_minus_def: "- x = Complex (- Re x) (- Im x)"
   19.53 +
   19.54 +definition
   19.55 +  complex_diff_def: "x - (y\<Colon>complex) = x + - y"
   19.56 +
   19.57 +lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
   19.58 +  by (simp add: complex_zero_def)
   19.59 +
   19.60 +lemma complex_Re_zero [simp]: "Re 0 = 0"
   19.61 +  by (simp add: complex_zero_def)
   19.62 +
   19.63 +lemma complex_Im_zero [simp]: "Im 0 = 0"
   19.64 +  by (simp add: complex_zero_def)
   19.65 +
   19.66 +lemma complex_add [simp]:
   19.67 +  "Complex a b + Complex c d = Complex (a + c) (b + d)"
   19.68 +  by (simp add: complex_add_def)
   19.69 +
   19.70 +lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y"
   19.71 +  by (simp add: complex_add_def)
   19.72 +
   19.73 +lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y"
   19.74 +  by (simp add: complex_add_def)
   19.75 +
   19.76 +lemma complex_minus [simp]:
   19.77 +  "- (Complex a b) = Complex (- a) (- b)"
   19.78 +  by (simp add: complex_minus_def)
   19.79 +
   19.80 +lemma complex_Re_minus [simp]: "Re (- x) = - Re x"
   19.81 +  by (simp add: complex_minus_def)
   19.82 +
   19.83 +lemma complex_Im_minus [simp]: "Im (- x) = - Im x"
   19.84 +  by (simp add: complex_minus_def)
   19.85 +
   19.86 +lemma complex_diff [simp]:
   19.87 +  "Complex a b - Complex c d = Complex (a - c) (b - d)"
   19.88 +  by (simp add: complex_diff_def)
   19.89 +
   19.90 +lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y"
   19.91 +  by (simp add: complex_diff_def)
   19.92 +
   19.93 +lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y"
   19.94 +  by (simp add: complex_diff_def)
   19.95 +
   19.96 +instance
   19.97 +  by intro_classes (simp_all add: complex_add_def complex_diff_def)
   19.98 +
   19.99 +end
  19.100 +
  19.101 +
  19.102 +
  19.103 +subsection {* Multiplication and Division *}
  19.104 +
  19.105 +instantiation complex :: "{field, division_by_zero}"
  19.106 +begin
  19.107 +
  19.108 +definition
  19.109 +  complex_one_def: "1 = Complex 1 0"
  19.110 +
  19.111 +definition
  19.112 +  complex_mult_def: "x * y =
  19.113 +    Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)"
  19.114 +
  19.115 +definition
  19.116 +  complex_inverse_def: "inverse x =
  19.117 +    Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))"
  19.118 +
  19.119 +definition
  19.120 +  complex_divide_def: "x / (y\<Colon>complex) = x * inverse y"
  19.121 +
  19.122 +lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)"
  19.123 +  by (simp add: complex_one_def)
  19.124 +
  19.125 +lemma complex_Re_one [simp]: "Re 1 = 1"
  19.126 +  by (simp add: complex_one_def)
  19.127 +
  19.128 +lemma complex_Im_one [simp]: "Im 1 = 0"
  19.129 +  by (simp add: complex_one_def)
  19.130 +
  19.131 +lemma complex_mult [simp]:
  19.132 +  "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)"
  19.133 +  by (simp add: complex_mult_def)
  19.134 +
  19.135 +lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y"
  19.136 +  by (simp add: complex_mult_def)
  19.137 +
  19.138 +lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y"
  19.139 +  by (simp add: complex_mult_def)
  19.140 +
  19.141 +lemma complex_inverse [simp]:
  19.142 +  "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))"
  19.143 +  by (simp add: complex_inverse_def)
  19.144 +
  19.145 +lemma complex_Re_inverse:
  19.146 +  "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
  19.147 +  by (simp add: complex_inverse_def)
  19.148 +
  19.149 +lemma complex_Im_inverse:
  19.150 +  "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
  19.151 +  by (simp add: complex_inverse_def)
  19.152 +
  19.153 +instance
  19.154 +  by intro_classes (simp_all add: complex_mult_def
  19.155 +  right_distrib left_distrib right_diff_distrib left_diff_distrib
  19.156 +  complex_inverse_def complex_divide_def
  19.157 +  power2_eq_square add_divide_distrib [symmetric]
  19.158 +  expand_complex_eq)
  19.159 +
  19.160 +end
  19.161 +
  19.162 +
  19.163 +subsection {* Exponentiation *}
  19.164 +
  19.165 +instantiation complex :: recpower
  19.166 +begin
  19.167 +
  19.168 +primrec power_complex where
  19.169 +  complexpow_0:     "z ^ 0     = (1\<Colon>complex)"
  19.170 +  | complexpow_Suc: "z ^ Suc n = (z\<Colon>complex) * z ^ n"
  19.171 +
  19.172 +instance by intro_classes simp_all
  19.173 +
  19.174 +end
  19.175 +
  19.176 +
  19.177 +subsection {* Numerals and Arithmetic *}
  19.178 +
  19.179 +instantiation complex :: number_ring
  19.180 +begin
  19.181 +
  19.182 +definition number_of_complex where
  19.183 +  complex_number_of_def: "number_of w = (of_int w \<Colon> complex)"
  19.184 +
  19.185 +instance
  19.186 +  by intro_classes (simp only: complex_number_of_def)
  19.187 +
  19.188 +end
  19.189 +
  19.190 +lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n"
  19.191 +by (induct n) simp_all
  19.192 +
  19.193 +lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0"
  19.194 +by (induct n) simp_all
  19.195 +
  19.196 +lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z"
  19.197 +by (cases z rule: int_diff_cases) simp
  19.198 +
  19.199 +lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
  19.200 +by (cases z rule: int_diff_cases) simp
  19.201 +
  19.202 +lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v"
  19.203 +unfolding number_of_eq by (rule complex_Re_of_int)
  19.204 +
  19.205 +lemma complex_Im_number_of [simp]: "Im (number_of v) = 0"
  19.206 +unfolding number_of_eq by (rule complex_Im_of_int)
  19.207 +
  19.208 +lemma Complex_eq_number_of [simp]:
  19.209 +  "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)"
  19.210 +by (simp add: expand_complex_eq)
  19.211 +
  19.212 +
  19.213 +subsection {* Scalar Multiplication *}
  19.214 +
  19.215 +instantiation complex :: real_field
  19.216 +begin
  19.217 +
  19.218 +definition
  19.219 +  complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)"
  19.220 +
  19.221 +lemma complex_scaleR [simp]:
  19.222 +  "scaleR r (Complex a b) = Complex (r * a) (r * b)"
  19.223 +  unfolding complex_scaleR_def by simp
  19.224 +
  19.225 +lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x"
  19.226 +  unfolding complex_scaleR_def by simp
  19.227 +
  19.228 +lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x"
  19.229 +  unfolding complex_scaleR_def by simp
  19.230 +
  19.231 +instance
  19.232 +proof
  19.233 +  fix a b :: real and x y :: complex
  19.234 +  show "scaleR a (x + y) = scaleR a x + scaleR a y"
  19.235 +    by (simp add: expand_complex_eq right_distrib)
  19.236 +  show "scaleR (a + b) x = scaleR a x + scaleR b x"
  19.237 +    by (simp add: expand_complex_eq left_distrib)
  19.238 +  show "scaleR a (scaleR b x) = scaleR (a * b) x"
  19.239 +    by (simp add: expand_complex_eq mult_assoc)
  19.240 +  show "scaleR 1 x = x"
  19.241 +    by (simp add: expand_complex_eq)
  19.242 +  show "scaleR a x * y = scaleR a (x * y)"
  19.243 +    by (simp add: expand_complex_eq ring_simps)
  19.244 +  show "x * scaleR a y = scaleR a (x * y)"
  19.245 +    by (simp add: expand_complex_eq ring_simps)
  19.246 +qed
  19.247 +
  19.248 +end
  19.249 +
  19.250 +
  19.251 +subsection{* Properties of Embedding from Reals *}
  19.252 +
  19.253 +abbreviation
  19.254 +  complex_of_real :: "real \<Rightarrow> complex" where
  19.255 +    "complex_of_real \<equiv> of_real"
  19.256 +
  19.257 +lemma complex_of_real_def: "complex_of_real r = Complex r 0"
  19.258 +by (simp add: of_real_def complex_scaleR_def)
  19.259 +
  19.260 +lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
  19.261 +by (simp add: complex_of_real_def)
  19.262 +
  19.263 +lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
  19.264 +by (simp add: complex_of_real_def)
  19.265 +
  19.266 +lemma Complex_add_complex_of_real [simp]:
  19.267 +     "Complex x y + complex_of_real r = Complex (x+r) y"
  19.268 +by (simp add: complex_of_real_def)
  19.269 +
  19.270 +lemma complex_of_real_add_Complex [simp]:
  19.271 +     "complex_of_real r + Complex x y = Complex (r+x) y"
  19.272 +by (simp add: complex_of_real_def)
  19.273 +
  19.274 +lemma Complex_mult_complex_of_real:
  19.275 +     "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
  19.276 +by (simp add: complex_of_real_def)
  19.277 +
  19.278 +lemma complex_of_real_mult_Complex:
  19.279 +     "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
  19.280 +by (simp add: complex_of_real_def)
  19.281 +
  19.282 +
  19.283 +subsection {* Vector Norm *}
  19.284 +
  19.285 +instantiation complex :: real_normed_field
  19.286 +begin
  19.287 +
  19.288 +definition
  19.289 +  complex_norm_def: "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
  19.290 +
  19.291 +abbreviation
  19.292 +  cmod :: "complex \<Rightarrow> real" where
  19.293 +  "cmod \<equiv> norm"
  19.294 +
  19.295 +definition
  19.296 +  complex_sgn_def: "sgn x = x /\<^sub>R cmod x"
  19.297 +
  19.298 +lemmas cmod_def = complex_norm_def
  19.299 +
  19.300 +lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
  19.301 +  by (simp add: complex_norm_def)
  19.302 +
  19.303 +instance
  19.304 +proof
  19.305 +  fix r :: real and x y :: complex
  19.306 +  show "0 \<le> norm x"
  19.307 +    by (induct x) simp
  19.308 +  show "(norm x = 0) = (x = 0)"
  19.309 +    by (induct x) simp
  19.310 +  show "norm (x + y) \<le> norm x + norm y"
  19.311 +    by (induct x, induct y)
  19.312 +       (simp add: real_sqrt_sum_squares_triangle_ineq)
  19.313 +  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
  19.314 +    by (induct x)
  19.315 +       (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult)
  19.316 +  show "norm (x * y) = norm x * norm y"
  19.317 +    by (induct x, induct y)
  19.318 +       (simp add: real_sqrt_mult [symmetric] power2_eq_square ring_simps)
  19.319 +  show "sgn x = x /\<^sub>R cmod x" by(simp add: complex_sgn_def)
  19.320 +qed
  19.321 +
  19.322 +end
  19.323 +
  19.324 +lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
  19.325 +by simp
  19.326 +
  19.327 +lemma cmod_complex_polar [simp]:
  19.328 +     "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
  19.329 +by (simp add: norm_mult)
  19.330 +
  19.331 +lemma complex_Re_le_cmod: "Re x \<le> cmod x"
  19.332 +unfolding complex_norm_def
  19.333 +by (rule real_sqrt_sum_squares_ge1)
  19.334 +
  19.335 +lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
  19.336 +by (rule order_trans [OF _ norm_ge_zero], simp)
  19.337 +
  19.338 +lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
  19.339 +by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
  19.340 +
  19.341 +lemmas real_sum_squared_expand = power2_sum [where 'a=real]
  19.342 +
  19.343 +lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x"
  19.344 +by (cases x) simp
  19.345 +
  19.346 +lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x"
  19.347 +by (cases x) simp
  19.348 +
  19.349 +subsection {* Completeness of the Complexes *}
  19.350 +
  19.351 +interpretation Re: bounded_linear ["Re"]
  19.352 +apply (unfold_locales, simp, simp)
  19.353 +apply (rule_tac x=1 in exI)
  19.354 +apply (simp add: complex_norm_def)
  19.355 +done
  19.356 +
  19.357 +interpretation Im: bounded_linear ["Im"]
  19.358 +apply (unfold_locales, simp, simp)
  19.359 +apply (rule_tac x=1 in exI)
  19.360 +apply (simp add: complex_norm_def)
  19.361 +done
  19.362 +
  19.363 +lemma LIMSEQ_Complex:
  19.364 +  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. Complex (X n) (Y n)) ----> Complex a b"
  19.365 +apply (rule LIMSEQ_I)
  19.366 +apply (subgoal_tac "0 < r / sqrt 2")
  19.367 +apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
  19.368 +apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
  19.369 +apply (rename_tac M N, rule_tac x="max M N" in exI, safe)
  19.370 +apply (simp add: real_sqrt_sum_squares_less)
  19.371 +apply (simp add: divide_pos_pos)
  19.372 +done
  19.373 +
  19.374 +instance complex :: banach
  19.375 +proof
  19.376 +  fix X :: "nat \<Rightarrow> complex"
  19.377 +  assume X: "Cauchy X"
  19.378 +  from Re.Cauchy [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))"
  19.379 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
  19.380 +  from Im.Cauchy [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))"
  19.381 +    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
  19.382 +  have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))"
  19.383 +    using LIMSEQ_Complex [OF 1 2] by simp
  19.384 +  thus "convergent X"
  19.385 +    by (rule convergentI)
  19.386 +qed
  19.387 +
  19.388 +
  19.389 +subsection {* The Complex Number @{term "\<i>"} *}
  19.390 +
  19.391 +definition
  19.392 +  "ii" :: complex  ("\<i>") where
  19.393 +  i_def: "ii \<equiv> Complex 0 1"
  19.394 +
  19.395 +lemma complex_Re_i [simp]: "Re ii = 0"
  19.396 +by (simp add: i_def)
  19.397 +
  19.398 +lemma complex_Im_i [simp]: "Im ii = 1"
  19.399 +by (simp add: i_def)
  19.400 +
  19.401 +lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
  19.402 +by (simp add: i_def)
  19.403 +
  19.404 +lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
  19.405 +by (simp add: expand_complex_eq)
  19.406 +
  19.407 +lemma complex_i_not_one [simp]: "ii \<noteq> 1"
  19.408 +by (simp add: expand_complex_eq)
  19.409 +
  19.410 +lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w"
  19.411 +by (simp add: expand_complex_eq)
  19.412 +
  19.413 +lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a"
  19.414 +by (simp add: expand_complex_eq)
  19.415 +
  19.416 +lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a"
  19.417 +by (simp add: expand_complex_eq)
  19.418 +
  19.419 +lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
  19.420 +by (simp add: i_def complex_of_real_def)
  19.421 +
  19.422 +lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
  19.423 +by (simp add: i_def complex_of_real_def)
  19.424 +
  19.425 +lemma i_squared [simp]: "ii * ii = -1"
  19.426 +by (simp add: i_def)
  19.427 +
  19.428 +lemma power2_i [simp]: "ii\<twosuperior> = -1"
  19.429 +by (simp add: power2_eq_square)
  19.430 +
  19.431 +lemma inverse_i [simp]: "inverse ii = - ii"
  19.432 +by (rule inverse_unique, simp)
  19.433 +
  19.434 +
  19.435 +subsection {* Complex Conjugation *}
  19.436 +
  19.437 +definition
  19.438 +  cnj :: "complex \<Rightarrow> complex" where
  19.439 +  "cnj z = Complex (Re z) (- Im z)"
  19.440 +
  19.441 +lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)"
  19.442 +by (simp add: cnj_def)
  19.443 +
  19.444 +lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x"
  19.445 +by (simp add: cnj_def)
  19.446 +
  19.447 +lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x"
  19.448 +by (simp add: cnj_def)
  19.449 +
  19.450 +lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
  19.451 +by (simp add: expand_complex_eq)
  19.452 +
  19.453 +lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
  19.454 +by (simp add: cnj_def)
  19.455 +
  19.456 +lemma complex_cnj_zero [simp]: "cnj 0 = 0"
  19.457 +by (simp add: expand_complex_eq)
  19.458 +
  19.459 +lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
  19.460 +by (simp add: expand_complex_eq)
  19.461 +
  19.462 +lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y"
  19.463 +by (simp add: expand_complex_eq)
  19.464 +
  19.465 +lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y"
  19.466 +by (simp add: expand_complex_eq)
  19.467 +
  19.468 +lemma complex_cnj_minus: "cnj (- x) = - cnj x"
  19.469 +by (simp add: expand_complex_eq)
  19.470 +
  19.471 +lemma complex_cnj_one [simp]: "cnj 1 = 1"
  19.472 +by (simp add: expand_complex_eq)
  19.473 +
  19.474 +lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y"
  19.475 +by (simp add: expand_complex_eq)
  19.476 +
  19.477 +lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)"
  19.478 +by (simp add: complex_inverse_def)
  19.479 +
  19.480 +lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y"
  19.481 +by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
  19.482 +
  19.483 +lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n"
  19.484 +by (induct n, simp_all add: complex_cnj_mult)
  19.485 +
  19.486 +lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n"
  19.487 +by (simp add: expand_complex_eq)
  19.488 +
  19.489 +lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z"
  19.490 +by (simp add: expand_complex_eq)
  19.491 +
  19.492 +lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w"
  19.493 +by (simp add: expand_complex_eq)
  19.494 +
  19.495 +lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)"
  19.496 +by (simp add: expand_complex_eq)
  19.497 +
  19.498 +lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
  19.499 +by (simp add: complex_norm_def)
  19.500 +
  19.501 +lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x"
  19.502 +by (simp add: expand_complex_eq)
  19.503 +
  19.504 +lemma complex_cnj_i [simp]: "cnj ii = - ii"
  19.505 +by (simp add: expand_complex_eq)
  19.506 +
  19.507 +lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)"
  19.508 +by (simp add: expand_complex_eq)
  19.509 +
  19.510 +lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii"
  19.511 +by (simp add: expand_complex_eq)
  19.512 +
  19.513 +lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
  19.514 +by (simp add: expand_complex_eq power2_eq_square)
  19.515 +
  19.516 +lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
  19.517 +by (simp add: norm_mult power2_eq_square)
  19.518 +
  19.519 +interpretation cnj: bounded_linear ["cnj"]
  19.520 +apply (unfold_locales)
  19.521 +apply (rule complex_cnj_add)
  19.522 +apply (rule complex_cnj_scaleR)
  19.523 +apply (rule_tac x=1 in exI, simp)
  19.524 +done
  19.525 +
  19.526 +
  19.527 +subsection{*The Functions @{term sgn} and @{term arg}*}
  19.528 +
  19.529 +text {*------------ Argand -------------*}
  19.530 +
  19.531 +definition
  19.532 +  arg :: "complex => real" where
  19.533 +  "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
  19.534 +
  19.535 +lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
  19.536 +by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute)
  19.537 +
  19.538 +lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
  19.539 +by (simp add: i_def complex_of_real_def)
  19.540 +
  19.541 +lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
  19.542 +by (simp add: i_def complex_one_def)
  19.543 +
  19.544 +lemma complex_eq_cancel_iff2 [simp]:
  19.545 +     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
  19.546 +by (simp add: complex_of_real_def)
  19.547 +
  19.548 +lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
  19.549 +by (simp add: complex_sgn_def divide_inverse)
  19.550 +
  19.551 +lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
  19.552 +by (simp add: complex_sgn_def divide_inverse)
  19.553 +
  19.554 +lemma complex_inverse_complex_split:
  19.555 +     "inverse(complex_of_real x + ii * complex_of_real y) =
  19.556 +      complex_of_real(x/(x ^ 2 + y ^ 2)) -
  19.557 +      ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
  19.558 +by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
  19.559 +
  19.560 +(*----------------------------------------------------------------------------*)
  19.561 +(* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
  19.562 +(* many of the theorems are not used - so should they be kept?                *)
  19.563 +(*----------------------------------------------------------------------------*)
  19.564 +
  19.565 +lemma cos_arg_i_mult_zero_pos:
  19.566 +   "0 < y ==> cos (arg(Complex 0 y)) = 0"
  19.567 +apply (simp add: arg_def abs_if)
  19.568 +apply (rule_tac a = "pi/2" in someI2, auto)
  19.569 +apply (rule order_less_trans [of _ 0], auto)
  19.570 +done
  19.571 +
  19.572 +lemma cos_arg_i_mult_zero_neg:
  19.573 +   "y < 0 ==> cos (arg(Complex 0 y)) = 0"
  19.574 +apply (simp add: arg_def abs_if)
  19.575 +apply (rule_tac a = "- pi/2" in someI2, auto)
  19.576 +apply (rule order_trans [of _ 0], auto)
  19.577 +done
  19.578 +
  19.579 +lemma cos_arg_i_mult_zero [simp]:
  19.580 +     "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
  19.581 +by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
  19.582 +
  19.583 +
  19.584 +subsection{*Finally! Polar Form for Complex Numbers*}
  19.585 +
  19.586 +definition
  19.587 +
  19.588 +  (* abbreviation for (cos a + i sin a) *)
  19.589 +  cis :: "real => complex" where
  19.590 +  "cis a = Complex (cos a) (sin a)"
  19.591 +
  19.592 +definition
  19.593 +  (* abbreviation for r*(cos a + i sin a) *)
  19.594 +  rcis :: "[real, real] => complex" where
  19.595 +  "rcis r a = complex_of_real r * cis a"
  19.596 +
  19.597 +definition
  19.598 +  (* e ^ (x + iy) *)
  19.599 +  expi :: "complex => complex" where
  19.600 +  "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
  19.601 +
  19.602 +lemma complex_split_polar:
  19.603 +     "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
  19.604 +apply (induct z)
  19.605 +apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
  19.606 +done
  19.607 +
  19.608 +lemma rcis_Ex: "\<exists>r a. z = rcis r a"
  19.609 +apply (induct z)
  19.610 +apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
  19.611 +done
  19.612 +
  19.613 +lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
  19.614 +by (simp add: rcis_def cis_def)
  19.615 +
  19.616 +lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
  19.617 +by (simp add: rcis_def cis_def)
  19.618 +
  19.619 +lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
  19.620 +proof -
  19.621 +  have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
  19.622 +    by (simp only: power_mult_distrib right_distrib)
  19.623 +  thus ?thesis by simp
  19.624 +qed
  19.625 +
  19.626 +lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
  19.627 +by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
  19.628 +
  19.629 +lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
  19.630 +by (simp add: cmod_def power2_eq_square)
  19.631 +
  19.632 +lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
  19.633 +by simp
  19.634 +
  19.635 +
  19.636 +(*---------------------------------------------------------------------------*)
  19.637 +(*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
  19.638 +(*---------------------------------------------------------------------------*)
  19.639 +
  19.640 +lemma cis_rcis_eq: "cis a = rcis 1 a"
  19.641 +by (simp add: rcis_def)
  19.642 +
  19.643 +lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
  19.644 +by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib
  19.645 +              complex_of_real_def)
  19.646 +
  19.647 +lemma cis_mult: "cis a * cis b = cis (a + b)"
  19.648 +by (simp add: cis_rcis_eq rcis_mult)
  19.649 +
  19.650 +lemma cis_zero [simp]: "cis 0 = 1"
  19.651 +by (simp add: cis_def complex_one_def)
  19.652 +
  19.653 +lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
  19.654 +by (simp add: rcis_def)
  19.655 +
  19.656 +lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
  19.657 +by (simp add: rcis_def)
  19.658 +
  19.659 +lemma complex_of_real_minus_one:
  19.660 +   "complex_of_real (-(1::real)) = -(1::complex)"
  19.661 +by (simp add: complex_of_real_def complex_one_def)
  19.662 +
  19.663 +lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
  19.664 +by (simp add: mult_assoc [symmetric])
  19.665 +
  19.666 +
  19.667 +lemma cis_real_of_nat_Suc_mult:
  19.668 +   "cis (real (Suc n) * a) = cis a * cis (real n * a)"
  19.669 +by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
  19.670 +
  19.671 +lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
  19.672 +apply (induct_tac "n")
  19.673 +apply (auto simp add: cis_real_of_nat_Suc_mult)
  19.674 +done
  19.675 +
  19.676 +lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
  19.677 +by (simp add: rcis_def power_mult_distrib DeMoivre)
  19.678 +
  19.679 +lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
  19.680 +by (simp add: cis_def complex_inverse_complex_split diff_minus)
  19.681 +
  19.682 +lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
  19.683 +by (simp add: divide_inverse rcis_def)
  19.684 +
  19.685 +lemma cis_divide: "cis a / cis b = cis (a - b)"
  19.686 +by (simp add: complex_divide_def cis_mult real_diff_def)
  19.687 +
  19.688 +lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
  19.689 +apply (simp add: complex_divide_def)
  19.690 +apply (case_tac "r2=0", simp)
  19.691 +apply (simp add: rcis_inverse rcis_mult real_diff_def)
  19.692 +done
  19.693 +
  19.694 +lemma Re_cis [simp]: "Re(cis a) = cos a"
  19.695 +by (simp add: cis_def)
  19.696 +
  19.697 +lemma Im_cis [simp]: "Im(cis a) = sin a"
  19.698 +by (simp add: cis_def)
  19.699 +
  19.700 +lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
  19.701 +by (auto simp add: DeMoivre)
  19.702 +
  19.703 +lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
  19.704 +by (auto simp add: DeMoivre)
  19.705 +
  19.706 +lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
  19.707 +by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac)
  19.708 +
  19.709 +lemma expi_zero [simp]: "expi (0::complex) = 1"
  19.710 +by (simp add: expi_def)
  19.711 +
  19.712 +lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
  19.713 +apply (insert rcis_Ex [of z])
  19.714 +apply (auto simp add: expi_def rcis_def mult_assoc [symmetric])
  19.715 +apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
  19.716 +done
  19.717 +
  19.718 +lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
  19.719 +by (simp add: expi_def cis_def)
  19.720 +
  19.721 +end
    20.1 --- a/src/HOL/Complex/Complex.thy	Fri Dec 05 11:26:07 2008 +0100
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,719 +0,0 @@
    20.4 -(*  Title:       Complex.thy
    20.5 -    ID:      $Id$
    20.6 -    Author:      Jacques D. Fleuriot
    20.7 -    Copyright:   2001 University of Edinburgh
    20.8 -    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
    20.9 -*)
   20.10 -
   20.11 -header {* Complex Numbers: Rectangular and Polar Representations *}
   20.12 -
   20.13 -theory Complex
   20.14 -imports "../Hyperreal/Transcendental"
   20.15 -begin
   20.16 -
   20.17 -datatype complex = Complex real real
   20.18 -
   20.19 -primrec
   20.20 -  Re :: "complex \<Rightarrow> real"
   20.21 -where
   20.22 -  Re: "Re (Complex x y) = x"
   20.23 -
   20.24 -primrec
   20.25 -  Im :: "complex \<Rightarrow> real"
   20.26 -where
   20.27 -  Im: "Im (Complex x y) = y"
   20.28 -
   20.29 -lemma complex_surj [simp]: "Complex (Re z) (Im z) = z"
   20.30 -  by (induct z) simp
   20.31 -
   20.32 -lemma complex_equality [intro?]: "\<lbrakk>Re x = Re y; Im x = Im y\<rbrakk> \<Longrightarrow> x = y"
   20.33 -  by (induct x, induct y) simp
   20.34 -
   20.35 -lemma expand_complex_eq: "x = y \<longleftrightarrow> Re x = Re y \<and> Im x = Im y"
   20.36 -  by (induct x, induct y) simp
   20.37 -
   20.38 -lemmas complex_Re_Im_cancel_iff = expand_complex_eq
   20.39 -
   20.40 -
   20.41 -subsection {* Addition and Subtraction *}
   20.42 -
   20.43 -instantiation complex :: ab_group_add
   20.44 -begin
   20.45 -
   20.46 -definition
   20.47 -  complex_zero_def: "0 = Complex 0 0"
   20.48 -
   20.49 -definition
   20.50 -  complex_add_def: "x + y = Complex (Re x + Re y) (Im x + Im y)"
   20.51 -
   20.52 -definition
   20.53 -  complex_minus_def: "- x = Complex (- Re x) (- Im x)"
   20.54 -
   20.55 -definition
   20.56 -  complex_diff_def: "x - (y\<Colon>complex) = x + - y"
   20.57 -
   20.58 -lemma Complex_eq_0 [simp]: "Complex a b = 0 \<longleftrightarrow> a = 0 \<and> b = 0"
   20.59 -  by (simp add: complex_zero_def)
   20.60 -
   20.61 -lemma complex_Re_zero [simp]: "Re 0 = 0"
   20.62 -  by (simp add: complex_zero_def)
   20.63 -
   20.64 -lemma complex_Im_zero [simp]: "Im 0 = 0"
   20.65 -  by (simp add: complex_zero_def)
   20.66 -
   20.67 -lemma complex_add [simp]:
   20.68 -  "Complex a b + Complex c d = Complex (a + c) (b + d)"
   20.69 -  by (simp add: complex_add_def)
   20.70 -
   20.71 -lemma complex_Re_add [simp]: "Re (x + y) = Re x + Re y"
   20.72 -  by (simp add: complex_add_def)
   20.73 -
   20.74 -lemma complex_Im_add [simp]: "Im (x + y) = Im x + Im y"
   20.75 -  by (simp add: complex_add_def)
   20.76 -
   20.77 -lemma complex_minus [simp]:
   20.78 -  "- (Complex a b) = Complex (- a) (- b)"
   20.79 -  by (simp add: complex_minus_def)
   20.80 -
   20.81 -lemma complex_Re_minus [simp]: "Re (- x) = - Re x"
   20.82 -  by (simp add: complex_minus_def)
   20.83 -
   20.84 -lemma complex_Im_minus [simp]: "Im (- x) = - Im x"
   20.85 -  by (simp add: complex_minus_def)
   20.86 -
   20.87 -lemma complex_diff [simp]:
   20.88 -  "Complex a b - Complex c d = Complex (a - c) (b - d)"
   20.89 -  by (simp add: complex_diff_def)
   20.90 -
   20.91 -lemma complex_Re_diff [simp]: "Re (x - y) = Re x - Re y"
   20.92 -  by (simp add: complex_diff_def)
   20.93 -
   20.94 -lemma complex_Im_diff [simp]: "Im (x - y) = Im x - Im y"
   20.95 -  by (simp add: complex_diff_def)
   20.96 -
   20.97 -instance
   20.98 -  by intro_classes (simp_all add: complex_add_def complex_diff_def)
   20.99 -
  20.100 -end
  20.101 -
  20.102 -
  20.103 -
  20.104 -subsection {* Multiplication and Division *}
  20.105 -
  20.106 -instantiation complex :: "{field, division_by_zero}"
  20.107 -begin
  20.108 -
  20.109 -definition
  20.110 -  complex_one_def: "1 = Complex 1 0"
  20.111 -
  20.112 -definition
  20.113 -  complex_mult_def: "x * y =
  20.114 -    Complex (Re x * Re y - Im x * Im y) (Re x * Im y + Im x * Re y)"
  20.115 -
  20.116 -definition
  20.117 -  complex_inverse_def: "inverse x =
  20.118 -    Complex (Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)) (- Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>))"
  20.119 -
  20.120 -definition
  20.121 -  complex_divide_def: "x / (y\<Colon>complex) = x * inverse y"
  20.122 -
  20.123 -lemma Complex_eq_1 [simp]: "(Complex a b = 1) = (a = 1 \<and> b = 0)"
  20.124 -  by (simp add: complex_one_def)
  20.125 -
  20.126 -lemma complex_Re_one [simp]: "Re 1 = 1"
  20.127 -  by (simp add: complex_one_def)
  20.128 -
  20.129 -lemma complex_Im_one [simp]: "Im 1 = 0"
  20.130 -  by (simp add: complex_one_def)
  20.131 -
  20.132 -lemma complex_mult [simp]:
  20.133 -  "Complex a b * Complex c d = Complex (a * c - b * d) (a * d + b * c)"
  20.134 -  by (simp add: complex_mult_def)
  20.135 -
  20.136 -lemma complex_Re_mult [simp]: "Re (x * y) = Re x * Re y - Im x * Im y"
  20.137 -  by (simp add: complex_mult_def)
  20.138 -
  20.139 -lemma complex_Im_mult [simp]: "Im (x * y) = Re x * Im y + Im x * Re y"
  20.140 -  by (simp add: complex_mult_def)
  20.141 -
  20.142 -lemma complex_inverse [simp]:
  20.143 -  "inverse (Complex a b) = Complex (a / (a\<twosuperior> + b\<twosuperior>)) (- b / (a\<twosuperior> + b\<twosuperior>))"
  20.144 -  by (simp add: complex_inverse_def)
  20.145 -
  20.146 -lemma complex_Re_inverse:
  20.147 -  "Re (inverse x) = Re x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
  20.148 -  by (simp add: complex_inverse_def)
  20.149 -
  20.150 -lemma complex_Im_inverse:
  20.151 -  "Im (inverse x) = - Im x / ((Re x)\<twosuperior> + (Im x)\<twosuperior>)"
  20.152 -  by (simp add: complex_inverse_def)
  20.153 -
  20.154 -instance
  20.155 -  by intro_classes (simp_all add: complex_mult_def
  20.156 -  right_distrib left_distrib right_diff_distrib left_diff_distrib
  20.157 -  complex_inverse_def complex_divide_def
  20.158 -  power2_eq_square add_divide_distrib [symmetric]
  20.159 -  expand_complex_eq)
  20.160 -
  20.161 -end
  20.162 -
  20.163 -
  20.164 -subsection {* Exponentiation *}
  20.165 -
  20.166 -instantiation complex :: recpower
  20.167 -begin
  20.168 -
  20.169 -primrec power_complex where
  20.170 -  complexpow_0:     "z ^ 0     = (1\<Colon>complex)"
  20.171 -  | complexpow_Suc: "z ^ Suc n = (z\<Colon>complex) * z ^ n"
  20.172 -
  20.173 -instance by intro_classes simp_all
  20.174 -
  20.175 -end
  20.176 -
  20.177 -
  20.178 -subsection {* Numerals and Arithmetic *}
  20.179 -
  20.180 -instantiation complex :: number_ring
  20.181 -begin
  20.182 -
  20.183 -definition number_of_complex where
  20.184 -  complex_number_of_def: "number_of w = (of_int w \<Colon> complex)"
  20.185 -
  20.186 -instance
  20.187 -  by intro_classes (simp only: complex_number_of_def)
  20.188 -
  20.189 -end
  20.190 -
  20.191 -lemma complex_Re_of_nat [simp]: "Re (of_nat n) = of_nat n"
  20.192 -by (induct n) simp_all
  20.193 -
  20.194 -lemma complex_Im_of_nat [simp]: "Im (of_nat n) = 0"
  20.195 -by (induct n) simp_all
  20.196 -
  20.197 -lemma complex_Re_of_int [simp]: "Re (of_int z) = of_int z"
  20.198 -by (cases z rule: int_diff_cases) simp
  20.199 -
  20.200 -lemma complex_Im_of_int [simp]: "Im (of_int z) = 0"
  20.201 -by (cases z rule: int_diff_cases) simp
  20.202 -
  20.203 -lemma complex_Re_number_of [simp]: "Re (number_of v) = number_of v"
  20.204 -unfolding number_of_eq by (rule complex_Re_of_int)
  20.205 -
  20.206 -lemma complex_Im_number_of [simp]: "Im (number_of v) = 0"
  20.207 -unfolding number_of_eq by (rule complex_Im_of_int)
  20.208 -
  20.209 -lemma Complex_eq_number_of [simp]:
  20.210 -  "(Complex a b = number_of w) = (a = number_of w \<and> b = 0)"
  20.211 -by (simp add: expand_complex_eq)
  20.212 -
  20.213 -
  20.214 -subsection {* Scalar Multiplication *}
  20.215 -
  20.216 -instantiation complex :: real_field
  20.217 -begin
  20.218 -
  20.219 -definition
  20.220 -  complex_scaleR_def: "scaleR r x = Complex (r * Re x) (r * Im x)"
  20.221 -
  20.222 -lemma complex_scaleR [simp]:
  20.223 -  "scaleR r (Complex a b) = Complex (r * a) (r * b)"
  20.224 -  unfolding complex_scaleR_def by simp
  20.225 -
  20.226 -lemma complex_Re_scaleR [simp]: "Re (scaleR r x) = r * Re x"
  20.227 -  unfolding complex_scaleR_def by simp
  20.228 -
  20.229 -lemma complex_Im_scaleR [simp]: "Im (scaleR r x) = r * Im x"
  20.230 -  unfolding complex_scaleR_def by simp
  20.231 -
  20.232 -instance
  20.233 -proof
  20.234 -  fix a b :: real and x y :: complex
  20.235 -  show "scaleR a (x + y) = scaleR a x + scaleR a y"
  20.236 -    by (simp add: expand_complex_eq right_distrib)
  20.237 -  show "scaleR (a + b) x = scaleR a x + scaleR b x"
  20.238 -    by (simp add: expand_complex_eq left_distrib)
  20.239 -  show "scaleR a (scaleR b x) = scaleR (a * b) x"
  20.240 -    by (simp add: expand_complex_eq mult_assoc)
  20.241 -  show "scaleR 1 x = x"
  20.242 -    by (simp add: expand_complex_eq)
  20.243 -  show "scaleR a x * y = scaleR a (x * y)"
  20.244 -    by (simp add: expand_complex_eq ring_simps)
  20.245 -  show "x * scaleR a y = scaleR a (x * y)"
  20.246 -    by (simp add: expand_complex_eq ring_simps)
  20.247 -qed
  20.248 -
  20.249 -end
  20.250 -
  20.251 -
  20.252 -subsection{* Properties of Embedding from Reals *}
  20.253 -
  20.254 -abbreviation
  20.255 -  complex_of_real :: "real \<Rightarrow> complex" where
  20.256 -    "complex_of_real \<equiv> of_real"
  20.257 -
  20.258 -lemma complex_of_real_def: "complex_of_real r = Complex r 0"
  20.259 -by (simp add: of_real_def complex_scaleR_def)
  20.260 -
  20.261 -lemma Re_complex_of_real [simp]: "Re (complex_of_real z) = z"
  20.262 -by (simp add: complex_of_real_def)
  20.263 -
  20.264 -lemma Im_complex_of_real [simp]: "Im (complex_of_real z) = 0"
  20.265 -by (simp add: complex_of_real_def)
  20.266 -
  20.267 -lemma Complex_add_complex_of_real [simp]:
  20.268 -     "Complex x y + complex_of_real r = Complex (x+r) y"
  20.269 -by (simp add: complex_of_real_def)
  20.270 -
  20.271 -lemma complex_of_real_add_Complex [simp]:
  20.272 -     "complex_of_real r + Complex x y = Complex (r+x) y"
  20.273 -by (simp add: complex_of_real_def)
  20.274 -
  20.275 -lemma Complex_mult_complex_of_real:
  20.276 -     "Complex x y * complex_of_real r = Complex (x*r) (y*r)"
  20.277 -by (simp add: complex_of_real_def)
  20.278 -
  20.279 -lemma complex_of_real_mult_Complex:
  20.280 -     "complex_of_real r * Complex x y = Complex (r*x) (r*y)"
  20.281 -by (simp add: complex_of_real_def)
  20.282 -
  20.283 -
  20.284 -subsection {* Vector Norm *}
  20.285 -
  20.286 -instantiation complex :: real_normed_field
  20.287 -begin
  20.288 -
  20.289 -definition
  20.290 -  complex_norm_def: "norm z = sqrt ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
  20.291 -
  20.292 -abbreviation
  20.293 -  cmod :: "complex \<Rightarrow> real" where
  20.294 -  "cmod \<equiv> norm"
  20.295 -
  20.296 -definition
  20.297 -  complex_sgn_def: "sgn x = x /\<^sub>R cmod x"
  20.298 -
  20.299 -lemmas cmod_def = complex_norm_def
  20.300 -
  20.301 -lemma complex_norm [simp]: "cmod (Complex x y) = sqrt (x\<twosuperior> + y\<twosuperior>)"
  20.302 -  by (simp add: complex_norm_def)
  20.303 -
  20.304 -instance
  20.305 -proof
  20.306 -  fix r :: real and x y :: complex
  20.307 -  show "0 \<le> norm x"
  20.308 -    by (induct x) simp
  20.309 -  show "(norm x = 0) = (x = 0)"
  20.310 -    by (induct x) simp
  20.311 -  show "norm (x + y) \<le> norm x + norm y"
  20.312 -    by (induct x, induct y)
  20.313 -       (simp add: real_sqrt_sum_squares_triangle_ineq)
  20.314 -  show "norm (scaleR r x) = \<bar>r\<bar> * norm x"
  20.315 -    by (induct x)
  20.316 -       (simp add: power_mult_distrib right_distrib [symmetric] real_sqrt_mult)
  20.317 -  show "norm (x * y) = norm x * norm y"
  20.318 -    by (induct x, induct y)
  20.319 -       (simp add: real_sqrt_mult [symmetric] power2_eq_square ring_simps)
  20.320 -  show "sgn x = x /\<^sub>R cmod x" by(simp add: complex_sgn_def)
  20.321 -qed
  20.322 -
  20.323 -end
  20.324 -
  20.325 -lemma cmod_unit_one [simp]: "cmod (Complex (cos a) (sin a)) = 1"
  20.326 -by simp
  20.327 -
  20.328 -lemma cmod_complex_polar [simp]:
  20.329 -     "cmod (complex_of_real r * Complex (cos a) (sin a)) = abs r"
  20.330 -by (simp add: norm_mult)
  20.331 -
  20.332 -lemma complex_Re_le_cmod: "Re x \<le> cmod x"
  20.333 -unfolding complex_norm_def
  20.334 -by (rule real_sqrt_sum_squares_ge1)
  20.335 -
  20.336 -lemma complex_mod_minus_le_complex_mod [simp]: "- cmod x \<le> cmod x"
  20.337 -by (rule order_trans [OF _ norm_ge_zero], simp)
  20.338 -
  20.339 -lemma complex_mod_triangle_ineq2 [simp]: "cmod(b + a) - cmod b \<le> cmod a"
  20.340 -by (rule ord_le_eq_trans [OF norm_triangle_ineq2], simp)
  20.341 -
  20.342 -lemmas real_sum_squared_expand = power2_sum [where 'a=real]
  20.343 -
  20.344 -lemma abs_Re_le_cmod: "\<bar>Re x\<bar> \<le> cmod x"
  20.345 -by (cases x) simp
  20.346 -
  20.347 -lemma abs_Im_le_cmod: "\<bar>Im x\<bar> \<le> cmod x"
  20.348 -by (cases x) simp
  20.349 -
  20.350 -subsection {* Completeness of the Complexes *}
  20.351 -
  20.352 -interpretation Re: bounded_linear ["Re"]
  20.353 -apply (unfold_locales, simp, simp)
  20.354 -apply (rule_tac x=1 in exI)
  20.355 -apply (simp add: complex_norm_def)
  20.356 -done
  20.357 -
  20.358 -interpretation Im: bounded_linear ["Im"]
  20.359 -apply (unfold_locales, simp, simp)
  20.360 -apply (rule_tac x=1 in exI)
  20.361 -apply (simp add: complex_norm_def)
  20.362 -done
  20.363 -
  20.364 -lemma LIMSEQ_Complex:
  20.365 -  "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. Complex (X n) (Y n)) ----> Complex a b"
  20.366 -apply (rule LIMSEQ_I)
  20.367 -apply (subgoal_tac "0 < r / sqrt 2")
  20.368 -apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
  20.369 -apply (drule_tac r="r / sqrt 2" in LIMSEQ_D, safe)
  20.370 -apply (rename_tac M N, rule_tac x="max M N" in exI, safe)
  20.371 -apply (simp add: real_sqrt_sum_squares_less)
  20.372 -apply (simp add: divide_pos_pos)
  20.373 -done
  20.374 -
  20.375 -instance complex :: banach
  20.376 -proof
  20.377 -  fix X :: "nat \<Rightarrow> complex"
  20.378 -  assume X: "Cauchy X"
  20.379 -  from Re.Cauchy [OF X] have 1: "(\<lambda>n. Re (X n)) ----> lim (\<lambda>n. Re (X n))"
  20.380 -    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
  20.381 -  from Im.Cauchy [OF X] have 2: "(\<lambda>n. Im (X n)) ----> lim (\<lambda>n. Im (X n))"
  20.382 -    by (simp add: Cauchy_convergent_iff convergent_LIMSEQ_iff)
  20.383 -  have "X ----> Complex (lim (\<lambda>n. Re (X n))) (lim (\<lambda>n. Im (X n)))"
  20.384 -    using LIMSEQ_Complex [OF 1 2] by simp
  20.385 -  thus "convergent X"
  20.386 -    by (rule convergentI)
  20.387 -qed
  20.388 -
  20.389 -
  20.390 -subsection {* The Complex Number @{term "\<i>"} *}
  20.391 -
  20.392 -definition
  20.393 -  "ii" :: complex  ("\<i>") where
  20.394 -  i_def: "ii \<equiv> Complex 0 1"
  20.395 -
  20.396 -lemma complex_Re_i [simp]: "Re ii = 0"
  20.397 -by (simp add: i_def)
  20.398 -
  20.399 -lemma complex_Im_i [simp]: "Im ii = 1"
  20.400 -by (simp add: i_def)
  20.401 -
  20.402 -lemma Complex_eq_i [simp]: "(Complex x y = ii) = (x = 0 \<and> y = 1)"
  20.403 -by (simp add: i_def)
  20.404 -
  20.405 -lemma complex_i_not_zero [simp]: "ii \<noteq> 0"
  20.406 -by (simp add: expand_complex_eq)
  20.407 -
  20.408 -lemma complex_i_not_one [simp]: "ii \<noteq> 1"
  20.409 -by (simp add: expand_complex_eq)
  20.410 -
  20.411 -lemma complex_i_not_number_of [simp]: "ii \<noteq> number_of w"
  20.412 -by (simp add: expand_complex_eq)
  20.413 -
  20.414 -lemma i_mult_Complex [simp]: "ii * Complex a b = Complex (- b) a"
  20.415 -by (simp add: expand_complex_eq)
  20.416 -
  20.417 -lemma Complex_mult_i [simp]: "Complex a b * ii = Complex (- b) a"
  20.418 -by (simp add: expand_complex_eq)
  20.419 -
  20.420 -lemma i_complex_of_real [simp]: "ii * complex_of_real r = Complex 0 r"
  20.421 -by (simp add: i_def complex_of_real_def)
  20.422 -
  20.423 -lemma complex_of_real_i [simp]: "complex_of_real r * ii = Complex 0 r"
  20.424 -by (simp add: i_def complex_of_real_def)
  20.425 -
  20.426 -lemma i_squared [simp]: "ii * ii = -1"
  20.427 -by (simp add: i_def)
  20.428 -
  20.429 -lemma power2_i [simp]: "ii\<twosuperior> = -1"
  20.430 -by (simp add: power2_eq_square)
  20.431 -
  20.432 -lemma inverse_i [simp]: "inverse ii = - ii"
  20.433 -by (rule inverse_unique, simp)
  20.434 -
  20.435 -
  20.436 -subsection {* Complex Conjugation *}
  20.437 -
  20.438 -definition
  20.439 -  cnj :: "complex \<Rightarrow> complex" where
  20.440 -  "cnj z = Complex (Re z) (- Im z)"
  20.441 -
  20.442 -lemma complex_cnj [simp]: "cnj (Complex a b) = Complex a (- b)"
  20.443 -by (simp add: cnj_def)
  20.444 -
  20.445 -lemma complex_Re_cnj [simp]: "Re (cnj x) = Re x"
  20.446 -by (simp add: cnj_def)
  20.447 -
  20.448 -lemma complex_Im_cnj [simp]: "Im (cnj x) = - Im x"
  20.449 -by (simp add: cnj_def)
  20.450 -
  20.451 -lemma complex_cnj_cancel_iff [simp]: "(cnj x = cnj y) = (x = y)"
  20.452 -by (simp add: expand_complex_eq)
  20.453 -
  20.454 -lemma complex_cnj_cnj [simp]: "cnj (cnj z) = z"
  20.455 -by (simp add: cnj_def)
  20.456 -
  20.457 -lemma complex_cnj_zero [simp]: "cnj 0 = 0"
  20.458 -by (simp add: expand_complex_eq)
  20.459 -
  20.460 -lemma complex_cnj_zero_iff [iff]: "(cnj z = 0) = (z = 0)"
  20.461 -by (simp add: expand_complex_eq)
  20.462 -
  20.463 -lemma complex_cnj_add: "cnj (x + y) = cnj x + cnj y"
  20.464 -by (simp add: expand_complex_eq)
  20.465 -
  20.466 -lemma complex_cnj_diff: "cnj (x - y) = cnj x - cnj y"
  20.467 -by (simp add: expand_complex_eq)
  20.468 -
  20.469 -lemma complex_cnj_minus: "cnj (- x) = - cnj x"
  20.470 -by (simp add: expand_complex_eq)
  20.471 -
  20.472 -lemma complex_cnj_one [simp]: "cnj 1 = 1"
  20.473 -by (simp add: expand_complex_eq)
  20.474 -
  20.475 -lemma complex_cnj_mult: "cnj (x * y) = cnj x * cnj y"
  20.476 -by (simp add: expand_complex_eq)
  20.477 -
  20.478 -lemma complex_cnj_inverse: "cnj (inverse x) = inverse (cnj x)"
  20.479 -by (simp add: complex_inverse_def)
  20.480 -
  20.481 -lemma complex_cnj_divide: "cnj (x / y) = cnj x / cnj y"
  20.482 -by (simp add: complex_divide_def complex_cnj_mult complex_cnj_inverse)
  20.483 -
  20.484 -lemma complex_cnj_power: "cnj (x ^ n) = cnj x ^ n"
  20.485 -by (induct n, simp_all add: complex_cnj_mult)
  20.486 -
  20.487 -lemma complex_cnj_of_nat [simp]: "cnj (of_nat n) = of_nat n"
  20.488 -by (simp add: expand_complex_eq)
  20.489 -
  20.490 -lemma complex_cnj_of_int [simp]: "cnj (of_int z) = of_int z"
  20.491 -by (simp add: expand_complex_eq)
  20.492 -
  20.493 -lemma complex_cnj_number_of [simp]: "cnj (number_of w) = number_of w"
  20.494 -by (simp add: expand_complex_eq)
  20.495 -
  20.496 -lemma complex_cnj_scaleR: "cnj (scaleR r x) = scaleR r (cnj x)"
  20.497 -by (simp add: expand_complex_eq)
  20.498 -
  20.499 -lemma complex_mod_cnj [simp]: "cmod (cnj z) = cmod z"
  20.500 -by (simp add: complex_norm_def)
  20.501 -
  20.502 -lemma complex_cnj_complex_of_real [simp]: "cnj (of_real x) = of_real x"
  20.503 -by (simp add: expand_complex_eq)
  20.504 -
  20.505 -lemma complex_cnj_i [simp]: "cnj ii = - ii"
  20.506 -by (simp add: expand_complex_eq)
  20.507 -
  20.508 -lemma complex_add_cnj: "z + cnj z = complex_of_real (2 * Re z)"
  20.509 -by (simp add: expand_complex_eq)
  20.510 -
  20.511 -lemma complex_diff_cnj: "z - cnj z = complex_of_real (2 * Im z) * ii"
  20.512 -by (simp add: expand_complex_eq)
  20.513 -
  20.514 -lemma complex_mult_cnj: "z * cnj z = complex_of_real ((Re z)\<twosuperior> + (Im z)\<twosuperior>)"
  20.515 -by (simp add: expand_complex_eq power2_eq_square)
  20.516 -
  20.517 -lemma complex_mod_mult_cnj: "cmod (z * cnj z) = (cmod z)\<twosuperior>"
  20.518 -by (simp add: norm_mult power2_eq_square)
  20.519 -
  20.520 -interpretation cnj: bounded_linear ["cnj"]
  20.521 -apply (unfold_locales)
  20.522 -apply (rule complex_cnj_add)
  20.523 -apply (rule complex_cnj_scaleR)
  20.524 -apply (rule_tac x=1 in exI, simp)
  20.525 -done
  20.526 -
  20.527 -
  20.528 -subsection{*The Functions @{term sgn} and @{term arg}*}
  20.529 -
  20.530 -text {*------------ Argand -------------*}
  20.531 -
  20.532 -definition
  20.533 -  arg :: "complex => real" where
  20.534 -  "arg z = (SOME a. Re(sgn z) = cos a & Im(sgn z) = sin a & -pi < a & a \<le> pi)"
  20.535 -
  20.536 -lemma sgn_eq: "sgn z = z / complex_of_real (cmod z)"
  20.537 -by (simp add: complex_sgn_def divide_inverse scaleR_conv_of_real mult_commute)
  20.538 -
  20.539 -lemma i_mult_eq: "ii * ii = complex_of_real (-1)"
  20.540 -by (simp add: i_def complex_of_real_def)
  20.541 -
  20.542 -lemma i_mult_eq2 [simp]: "ii * ii = -(1::complex)"
  20.543 -by (simp add: i_def complex_one_def)
  20.544 -
  20.545 -lemma complex_eq_cancel_iff2 [simp]:
  20.546 -     "(Complex x y = complex_of_real xa) = (x = xa & y = 0)"
  20.547 -by (simp add: complex_of_real_def)
  20.548 -
  20.549 -lemma Re_sgn [simp]: "Re(sgn z) = Re(z)/cmod z"
  20.550 -by (simp add: complex_sgn_def divide_inverse)
  20.551 -
  20.552 -lemma Im_sgn [simp]: "Im(sgn z) = Im(z)/cmod z"
  20.553 -by (simp add: complex_sgn_def divide_inverse)
  20.554 -
  20.555 -lemma complex_inverse_complex_split:
  20.556 -     "inverse(complex_of_real x + ii * complex_of_real y) =
  20.557 -      complex_of_real(x/(x ^ 2 + y ^ 2)) -
  20.558 -      ii * complex_of_real(y/(x ^ 2 + y ^ 2))"
  20.559 -by (simp add: complex_of_real_def i_def diff_minus divide_inverse)
  20.560 -
  20.561 -(*----------------------------------------------------------------------------*)
  20.562 -(* Many of the theorems below need to be moved elsewhere e.g. Transc. Also *)
  20.563 -(* many of the theorems are not used - so should they be kept?                *)
  20.564 -(*----------------------------------------------------------------------------*)
  20.565 -
  20.566 -lemma cos_arg_i_mult_zero_pos:
  20.567 -   "0 < y ==> cos (arg(Complex 0 y)) = 0"
  20.568 -apply (simp add: arg_def abs_if)
  20.569 -apply (rule_tac a = "pi/2" in someI2, auto)
  20.570 -apply (rule order_less_trans [of _ 0], auto)
  20.571 -done
  20.572 -
  20.573 -lemma cos_arg_i_mult_zero_neg:
  20.574 -   "y < 0 ==> cos (arg(Complex 0 y)) = 0"
  20.575 -apply (simp add: arg_def abs_if)
  20.576 -apply (rule_tac a = "- pi/2" in someI2, auto)
  20.577 -apply (rule order_trans [of _ 0], auto)
  20.578 -done
  20.579 -
  20.580 -lemma cos_arg_i_mult_zero [simp]:
  20.581 -     "y \<noteq> 0 ==> cos (arg(Complex 0 y)) = 0"
  20.582 -by (auto simp add: linorder_neq_iff cos_arg_i_mult_zero_pos cos_arg_i_mult_zero_neg)
  20.583 -
  20.584 -
  20.585 -subsection{*Finally! Polar Form for Complex Numbers*}
  20.586 -
  20.587 -definition
  20.588 -
  20.589 -  (* abbreviation for (cos a + i sin a) *)
  20.590 -  cis :: "real => complex" where
  20.591 -  "cis a = Complex (cos a) (sin a)"
  20.592 -
  20.593 -definition
  20.594 -  (* abbreviation for r*(cos a + i sin a) *)
  20.595 -  rcis :: "[real, real] => complex" where
  20.596 -  "rcis r a = complex_of_real r * cis a"
  20.597 -
  20.598 -definition
  20.599 -  (* e ^ (x + iy) *)
  20.600 -  expi :: "complex => complex" where
  20.601 -  "expi z = complex_of_real(exp (Re z)) * cis (Im z)"
  20.602 -
  20.603 -lemma complex_split_polar:
  20.604 -     "\<exists>r a. z = complex_of_real r * (Complex (cos a) (sin a))"
  20.605 -apply (induct z)
  20.606 -apply (auto simp add: polar_Ex complex_of_real_mult_Complex)
  20.607 -done
  20.608 -
  20.609 -lemma rcis_Ex: "\<exists>r a. z = rcis r a"
  20.610 -apply (induct z)
  20.611 -apply (simp add: rcis_def cis_def polar_Ex complex_of_real_mult_Complex)
  20.612 -done
  20.613 -
  20.614 -lemma Re_rcis [simp]: "Re(rcis r a) = r * cos a"
  20.615 -by (simp add: rcis_def cis_def)
  20.616 -
  20.617 -lemma Im_rcis [simp]: "Im(rcis r a) = r * sin a"
  20.618 -by (simp add: rcis_def cis_def)
  20.619 -
  20.620 -lemma sin_cos_squared_add2_mult: "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior>"
  20.621 -proof -
  20.622 -  have "(r * cos a)\<twosuperior> + (r * sin a)\<twosuperior> = r\<twosuperior> * ((cos a)\<twosuperior> + (sin a)\<twosuperior>)"
  20.623 -    by (simp only: power_mult_distrib right_distrib)
  20.624 -  thus ?thesis by simp
  20.625 -qed
  20.626 -
  20.627 -lemma complex_mod_rcis [simp]: "cmod(rcis r a) = abs r"
  20.628 -by (simp add: rcis_def cis_def sin_cos_squared_add2_mult)
  20.629 -
  20.630 -lemma complex_mod_sqrt_Re_mult_cnj: "cmod z = sqrt (Re (z * cnj z))"
  20.631 -by (simp add: cmod_def power2_eq_square)
  20.632 -
  20.633 -lemma complex_In_mult_cnj_zero [simp]: "Im (z * cnj z) = 0"
  20.634 -by simp
  20.635 -
  20.636 -
  20.637 -(*---------------------------------------------------------------------------*)
  20.638 -(*  (r1 * cis a) * (r2 * cis b) = r1 * r2 * cis (a + b)                      *)
  20.639 -(*---------------------------------------------------------------------------*)
  20.640 -
  20.641 -lemma cis_rcis_eq: "cis a = rcis 1 a"
  20.642 -by (simp add: rcis_def)
  20.643 -
  20.644 -lemma rcis_mult: "rcis r1 a * rcis r2 b = rcis (r1*r2) (a + b)"
  20.645 -by (simp add: rcis_def cis_def cos_add sin_add right_distrib right_diff_distrib
  20.646 -              complex_of_real_def)
  20.647 -
  20.648 -lemma cis_mult: "cis a * cis b = cis (a + b)"
  20.649 -by (simp add: cis_rcis_eq rcis_mult)
  20.650 -
  20.651 -lemma cis_zero [simp]: "cis 0 = 1"
  20.652 -by (simp add: cis_def complex_one_def)
  20.653 -
  20.654 -lemma rcis_zero_mod [simp]: "rcis 0 a = 0"
  20.655 -by (simp add: rcis_def)
  20.656 -
  20.657 -lemma rcis_zero_arg [simp]: "rcis r 0 = complex_of_real r"
  20.658 -by (simp add: rcis_def)
  20.659 -
  20.660 -lemma complex_of_real_minus_one:
  20.661 -   "complex_of_real (-(1::real)) = -(1::complex)"
  20.662 -by (simp add: complex_of_real_def complex_one_def)
  20.663 -
  20.664 -lemma complex_i_mult_minus [simp]: "ii * (ii * x) = - x"
  20.665 -by (simp add: mult_assoc [symmetric])
  20.666 -
  20.667 -
  20.668 -lemma cis_real_of_nat_Suc_mult:
  20.669 -   "cis (real (Suc n) * a) = cis a * cis (real n * a)"
  20.670 -by (simp add: cis_def real_of_nat_Suc left_distrib cos_add sin_add right_distrib)
  20.671 -
  20.672 -lemma DeMoivre: "(cis a) ^ n = cis (real n * a)"
  20.673 -apply (induct_tac "n")
  20.674 -apply (auto simp add: cis_real_of_nat_Suc_mult)
  20.675 -done
  20.676 -
  20.677 -lemma DeMoivre2: "(rcis r a) ^ n = rcis (r ^ n) (real n * a)"
  20.678 -by (simp add: rcis_def power_mult_distrib DeMoivre)
  20.679 -
  20.680 -lemma cis_inverse [simp]: "inverse(cis a) = cis (-a)"
  20.681 -by (simp add: cis_def complex_inverse_complex_split diff_minus)
  20.682 -
  20.683 -lemma rcis_inverse: "inverse(rcis r a) = rcis (1/r) (-a)"
  20.684 -by (simp add: divide_inverse rcis_def)
  20.685 -
  20.686 -lemma cis_divide: "cis a / cis b = cis (a - b)"
  20.687 -by (simp add: complex_divide_def cis_mult real_diff_def)
  20.688 -
  20.689 -lemma rcis_divide: "rcis r1 a / rcis r2 b = rcis (r1/r2) (a - b)"
  20.690 -apply (simp add: complex_divide_def)
  20.691 -apply (case_tac "r2=0", simp)
  20.692 -apply (simp add: rcis_inverse rcis_mult real_diff_def)
  20.693 -done
  20.694 -
  20.695 -lemma Re_cis [simp]: "Re(cis a) = cos a"
  20.696 -by (simp add: cis_def)
  20.697 -
  20.698 -lemma Im_cis [simp]: "Im(cis a) = sin a"
  20.699 -by (simp add: cis_def)
  20.700 -
  20.701 -lemma cos_n_Re_cis_pow_n: "cos (real n * a) = Re(cis a ^ n)"
  20.702 -by (auto simp add: DeMoivre)
  20.703 -
  20.704 -lemma sin_n_Im_cis_pow_n: "sin (real n * a) = Im(cis a ^ n)"
  20.705 -by (auto simp add: DeMoivre)
  20.706 -
  20.707 -lemma expi_add: "expi(a + b) = expi(a) * expi(b)"
  20.708 -by (simp add: expi_def exp_add cis_mult [symmetric] mult_ac)
  20.709 -
  20.710 -lemma expi_zero [simp]: "expi (0::complex) = 1"
  20.711 -by (simp add: expi_def)
  20.712 -
  20.713 -lemma complex_expi_Ex: "\<exists>a r. z = complex_of_real r * expi a"
  20.714 -apply (insert rcis_Ex [of z])
  20.715 -apply (auto simp add: expi_def rcis_def mult_assoc [symmetric])
  20.716 -apply (rule_tac x = "ii * complex_of_real a" in exI, auto)
  20.717 -done
  20.718 -
  20.719 -lemma expi_two_pi_i [simp]: "expi((2::complex) * complex_of_real pi * ii) = 1"
  20.720 -by (simp add: expi_def cis_def)
  20.721 -
  20.722 -end
    21.1 --- a/src/HOL/Complex/Complex_Main.thy	Fri Dec 05 11:26:07 2008 +0100
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,22 +0,0 @@
    21.4 -(*  Title:      HOL/Complex/Complex_Main.thy
    21.5 -    ID:         $Id$
    21.6 -    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
    21.7 -    Copyright   2003  University of Cambridge
    21.8 -*)
    21.9 -
   21.10 -header{*Comprehensive Complex Theory*}
   21.11 -
   21.12 -theory Complex_Main
   21.13 -imports
   21.14 -  "../Main"
   21.15 -  "../Real/ContNotDenum"
   21.16 -  "../Real/Real"
   21.17 -  Fundamental_Theorem_Algebra
   21.18 -  "../Hyperreal/Log"
   21.19 -  "../Hyperreal/Ln"
   21.20 -  "../Hyperreal/Taylor"
   21.21 -  "../Hyperreal/Integration"
   21.22 -  "../Hyperreal/FrechetDeriv"
   21.23 -begin
   21.24 -
   21.25 -end
    22.1 --- a/src/HOL/Complex/Fundamental_Theorem_Algebra.thy	Fri Dec 05 11:26:07 2008 +0100
    22.2 +++ b/src/HOL/Complex/Fundamental_Theorem_Algebra.thy	Fri Dec 05 11:42:27 2008 +0100
    22.3 @@ -1,12 +1,11 @@
    22.4  (*  Title:       Fundamental_Theorem_Algebra.thy
    22.5 -    ID:          $Id$
    22.6      Author:      Amine Chaieb
    22.7  *)
    22.8  
    22.9  header{*Fundamental Theorem of Algebra*}
   22.10  
   22.11  theory Fundamental_Theorem_Algebra
   22.12 -imports "~~/src/HOL/Library/Univ_Poly" "~~/src/HOL/Library/Dense_Linear_Order" Complex
   22.13 +imports "~~/src/HOL/Univ_Poly" "~~/src/HOL/Library/Dense_Linear_Order" "~~/src/HOL/Complex"
   22.14  begin
   22.15  
   22.16  subsection {* Square root of complex numbers *}
    23.1 --- a/src/HOL/Complex/ex/Arithmetic_Series_Complex.thy	Fri Dec 05 11:26:07 2008 +0100
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,24 +0,0 @@
    23.4 -(*  Title:      HOL/Complex/ex/Arithmetic_Series_Complex
    23.5 -    ID:         $Id$
    23.6 -    Author:     Benjamin Porter, 2006
    23.7 -*)
    23.8 -
    23.9 -
   23.10 -header {* Arithmetic Series for Reals *}
   23.11 -
   23.12 -theory Arithmetic_Series_Complex
   23.13 -imports Complex_Main 
   23.14 -begin
   23.15 -
   23.16 -lemma arith_series_real:
   23.17 -  "(2::real) * (\<Sum>i\<in>{..<n}. a + of_nat i * d) =
   23.18 -  of_nat n * (a + (a + of_nat(n - 1)*d))"
   23.19 -proof -
   23.20 -  have
   23.21 -    "((1::real) + 1) * (\<Sum>i\<in>{..<n}. a + of_nat(i)*d) =
   23.22 -    of_nat(n) * (a + (a + of_nat(n - 1)*d))"
   23.23 -    by (rule arith_series_general)
   23.24 -  thus ?thesis by simp
   23.25 -qed
   23.26 -
   23.27 -end
    24.1 --- a/src/HOL/Complex/ex/BigO_Complex.thy	Fri Dec 05 11:26:07 2008 +0100
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,50 +0,0 @@
    24.4 -(*  Title:      HOL/Complex/ex/BigO_Complex.thy
    24.5 -    ID:		$Id$
    24.6 -    Authors:    Jeremy Avigad and Kevin Donnelly
    24.7 -*)
    24.8 -
    24.9 -header {* Big O notation -- continued *}
   24.10 -
   24.11 -theory BigO_Complex
   24.12 -imports BigO Complex
   24.13 -begin
   24.14 -
   24.15 -text {*
   24.16 -  Additional lemmas that require the \texttt{HOL-Complex} logic image.
   24.17 -*}
   24.18 -
   24.19 -lemma bigo_LIMSEQ1: "f =o O(g) ==> g ----> 0 ==> f ----> (0::real)"
   24.20 -  apply (simp add: LIMSEQ_def bigo_alt_def)
   24.21 -  apply clarify
   24.22 -  apply (drule_tac x = "r / c" in spec)
   24.23 -  apply (drule mp)
   24.24 -  apply (erule divide_pos_pos)
   24.25 -  apply assumption
   24.26 -  apply clarify
   24.27 -  apply (rule_tac x = no in exI)
   24.28 -  apply (rule allI)
   24.29 -  apply (drule_tac x = n in spec)+
   24.30 -  apply (rule impI)
   24.31 -  apply (drule mp)
   24.32 -  apply assumption
   24.33 -  apply (rule order_le_less_trans)
   24.34 -  apply assumption
   24.35 -  apply (rule order_less_le_trans)
   24.36 -  apply (subgoal_tac "c * abs(g n) < c * (r / c)")
   24.37 -  apply assumption
   24.38 -  apply (erule mult_strict_left_mono)
   24.39 -  apply assumption
   24.40 -  apply simp
   24.41 -done
   24.42 -
   24.43 -lemma bigo_LIMSEQ2: "f =o g +o O(h) ==> h ----> 0 ==> f ----> a 
   24.44 -    ==> g ----> (a::real)"
   24.45 -  apply (drule set_plus_imp_minus)
   24.46 -  apply (drule bigo_LIMSEQ1)
   24.47 -  apply assumption
   24.48 -  apply (simp only: fun_diff_def)
   24.49 -  apply (erule LIMSEQ_diff_approach_zero2)
   24.50 -  apply assumption
   24.51 -done
   24.52 -
   24.53 -end
    25.1 --- a/src/HOL/Complex/ex/BinEx.thy	Fri Dec 05 11:26:07 2008 +0100
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,399 +0,0 @@
    25.4 -(*  Title:      HOL/Complex/ex/BinEx.thy
    25.5 -    ID:         $Id$
    25.6 -    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
    25.7 -    Copyright   1999  University of Cambridge
    25.8 -*)
    25.9 -
   25.10 -header {* Binary arithmetic examples *}
   25.11 -
   25.12 -theory BinEx
   25.13 -imports Complex_Main
   25.14 -begin
   25.15 -
   25.16 -text {*
   25.17 -  Examples of performing binary arithmetic by simplification.  This time
   25.18 -  we use the reals, though the representation is just of integers.
   25.19 -*}
   25.20 -
   25.21 -subsection{*Real Arithmetic*}
   25.22 -
   25.23 -subsubsection {*Addition *}
   25.24 -
   25.25 -lemma "(1359::real) + -2468 = -1109"
   25.26 -by simp
   25.27 -
   25.28 -lemma "(93746::real) + -46375 = 47371"
   25.29 -by simp
   25.30 -
   25.31 -
   25.32 -subsubsection {*Negation *}
   25.33 -
   25.34 -lemma "- (65745::real) = -65745"
   25.35 -by simp
   25.36 -
   25.37 -lemma "- (-54321::real) = 54321"
   25.38 -by simp
   25.39 -
   25.40 -
   25.41 -subsubsection {*Multiplication *}
   25.42 -
   25.43 -lemma "(-84::real) * 51 = -4284"
   25.44 -by simp
   25.45 -
   25.46 -lemma "(255::real) * 255 = 65025"
   25.47 -by simp
   25.48 -
   25.49 -lemma "(1359::real) * -2468 = -3354012"
   25.50 -by simp
   25.51 -
   25.52 -
   25.53 -subsubsection {*Inequalities *}
   25.54 -
   25.55 -lemma "(89::real) * 10 \<noteq> 889"
   25.56 -by simp
   25.57 -
   25.58 -lemma "(13::real) < 18 - 4"
   25.59 -by simp
   25.60 -
   25.61 -lemma "(-345::real) < -242 + -100"
   25.62 -by simp
   25.63 -
   25.64 -lemma "(13557456::real) < 18678654"
   25.65 -by simp
   25.66 -
   25.67 -lemma "(999999::real) \<le> (1000001 + 1) - 2"
   25.68 -by simp
   25.69 -
   25.70 -lemma "(1234567::real) \<le> 1234567"
   25.71 -by simp
   25.72 -
   25.73 -
   25.74 -subsubsection {*Powers *}
   25.75 -
   25.76 -lemma "2 ^ 15 = (32768::real)"
   25.77 -by simp
   25.78 -
   25.79 -lemma "-3 ^ 7 = (-2187::real)"
   25.80 -by simp
   25.81 -
   25.82 -lemma "13 ^ 7 = (62748517::real)"
   25.83 -by simp
   25.84 -
   25.85 -lemma "3 ^ 15 = (14348907::real)"
   25.86 -by simp
   25.87 -
   25.88 -lemma "-5 ^ 11 = (-48828125::real)"
   25.89 -by simp
   25.90 -
   25.91 -
   25.92 -subsubsection {*Tests *}
   25.93 -
   25.94 -lemma "(x + y = x) = (y = (0::real))"
   25.95 -by arith
   25.96 -
   25.97 -lemma "(x + y = y) = (x = (0::real))"
   25.98 -by arith
   25.99 -
  25.100 -lemma "(x + y = (0::real)) = (x = -y)"
  25.101 -by arith
  25.102 -
  25.103 -lemma "(x + y = (0::real)) = (y = -x)"
  25.104 -by arith
  25.105 -
  25.106 -lemma "((x + y) < (x + z)) = (y < (z::real))"
  25.107 -by arith
  25.108 -
  25.109 -lemma "((x + z) < (y + z)) = (x < (y::real))"
  25.110 -by arith
  25.111 -
  25.112 -lemma "(\<not> x < y) = (y \<le> (x::real))"
  25.113 -by arith
  25.114 -
  25.115 -lemma "\<not> (x < y \<and> y < (x::real))"
  25.116 -by arith
  25.117 -
  25.118 -lemma "(x::real) < y ==> \<not> y < x"
  25.119 -by arith
  25.120 -
  25.121 -lemma "((x::real) \<noteq> y) = (x < y \<or> y < x)"
  25.122 -by arith
  25.123 -
  25.124 -lemma "(\<not> x \<le> y) = (y < (x::real))"
  25.125 -by arith
  25.126 -
  25.127 -lemma "x \<le> y \<or> y \<le> (x::real)"
  25.128 -by arith
  25.129 -
  25.130 -lemma "x \<le> y \<or> y < (x::real)"
  25.131 -by arith
  25.132 -
  25.133 -lemma "x < y \<or> y \<le> (x::real)"
  25.134 -by arith
  25.135 -
  25.136 -lemma "x \<le> (x::real)"
  25.137 -by arith
  25.138 -
  25.139 -lemma "((x::real) \<le> y) = (x < y \<or> x = y)"
  25.140 -by arith
  25.141 -
  25.142 -lemma "((x::real) \<le> y \<and> y \<le> x) = (x = y)"
  25.143 -by arith
  25.144 -
  25.145 -lemma "\<not>(x < y \<and> y \<le> (x::real))"
  25.146 -by arith
  25.147 -
  25.148 -lemma "\<not>(x \<le> y \<and> y < (x::real))"
  25.149 -by arith
  25.150 -
  25.151 -lemma "(-x < (0::real)) = (0 < x)"
  25.152 -by arith
  25.153 -
  25.154 -lemma "((0::real) < -x) = (x < 0)"
  25.155 -by arith
  25.156 -
  25.157 -lemma "(-x \<le> (0::real)) = (0 \<le> x)"
  25.158 -by arith
  25.159 -
  25.160 -lemma "((0::real) \<le> -x) = (x \<le> 0)"
  25.161 -by arith
  25.162 -
  25.163 -lemma "(x::real) = y \<or> x < y \<or> y < x"
  25.164 -by arith
  25.165 -
  25.166 -lemma "(x::real) = 0 \<or> 0 < x \<or> 0 < -x"
  25.167 -by arith
  25.168 -
  25.169 -lemma "(0::real) \<le> x \<or> 0 \<le> -x"
  25.170 -by arith
  25.171 -
  25.172 -lemma "((x::real) + y \<le> x + z) = (y \<le> z)"
  25.173 -by arith
  25.174 -
  25.175 -lemma "((x::real) + z \<le> y + z) = (x \<le> y)"
  25.176 -by arith
  25.177 -
  25.178 -lemma "(w::real) < x \<and> y < z ==> w + y < x + z"
  25.179 -by arith
  25.180 -
  25.181 -lemma "(w::real) \<le> x \<and> y \<le> z ==> w + y \<le> x + z"
  25.182 -by arith
  25.183 -
  25.184 -lemma "(0::real) \<le> x \<and> 0 \<le> y ==> 0 \<le> x + y"
  25.185 -by arith
  25.186 -
  25.187 -lemma "(0::real) < x \<and> 0 < y ==> 0 < x + y"
  25.188 -by arith
  25.189 -
  25.190 -lemma "(-x < y) = (0 < x + (y::real))"
  25.191 -by arith
  25.192 -
  25.193 -lemma "(x < -y) = (x + y < (0::real))"
  25.194 -by arith
  25.195 -
  25.196 -lemma "(y < x + -z) = (y + z < (x::real))"
  25.197 -by arith
  25.198 -
  25.199 -lemma "(x + -y < z) = (x < z + (y::real))"
  25.200 -by arith
  25.201 -
  25.202 -lemma "x \<le> y ==> x < y + (1::real)"
  25.203 -by arith
  25.204 -
  25.205 -lemma "(x - y) + y = (x::real)"
  25.206 -by arith
  25.207 -
  25.208 -lemma "y + (x - y) = (x::real)"
  25.209 -by arith
  25.210 -
  25.211 -lemma "x - x = (0::real)"
  25.212 -by arith
  25.213 -
  25.214 -lemma "(x - y = 0) = (x = (y::real))"
  25.215 -by arith
  25.216 -
  25.217 -lemma "((0::real) \<le> x + x) = (0 \<le> x)"
  25.218 -by arith
  25.219 -
  25.220 -lemma "(-x \<le> x) = ((0::real) \<le> x)"
  25.221 -by arith
  25.222 -
  25.223 -lemma "(x \<le> -x) = (x \<le> (0::real))"
  25.224 -by arith
  25.225 -
  25.226 -lemma "(-x = (0::real)) = (x = 0)"
  25.227 -by arith
  25.228 -
  25.229 -lemma "-(x - y) = y - (x::real)"
  25.230 -by arith
  25.231 -
  25.232 -lemma "((0::real) < x - y) = (y < x)"
  25.233 -by arith
  25.234 -
  25.235 -lemma "((0::real) \<le> x - y) = (y \<le> x)"
  25.236 -by arith
  25.237 -
  25.238 -lemma "(x + y) - x = (y::real)"
  25.239 -by arith
  25.240 -
  25.241 -lemma "(-x = y) = (x = (-y::real))"
  25.242 -by arith
  25.243 -
  25.244 -lemma "x < (y::real) ==> \<not>(x = y)"
  25.245 -by arith
  25.246 -
  25.247 -lemma "(x \<le> x + y) = ((0::real) \<le> y)"
  25.248 -by arith
  25.249 -
  25.250 -lemma "(y \<le> x + y) = ((0::real) \<le> x)"
  25.251 -by arith
  25.252 -
  25.253 -lemma "(x < x + y) = ((0::real) < y)"
  25.254 -by arith
  25.255 -
  25.256 -lemma "(y < x + y) = ((0::real) < x)"
  25.257 -by arith
  25.258 -
  25.259 -lemma "(x - y) - x = (-y::real)"
  25.260 -by arith
  25.261 -
  25.262 -lemma "(x + y < z) = (x < z - (y::real))"
  25.263 -by arith
  25.264 -
  25.265 -lemma "(x - y < z) = (x < z + (y::real))"
  25.266 -by arith
  25.267 -
  25.268 -lemma "(x < y - z) = (x + z < (y::real))"
  25.269 -by arith
  25.270 -
  25.271 -lemma "(x \<le> y - z) = (x + z \<le> (y::real))"
  25.272 -by arith
  25.273 -
  25.274 -lemma "(x - y \<le> z) = (x \<le> z + (y::real))"
  25.275 -by arith
  25.276 -
  25.277 -lemma "(-x < -y) = (y < (x::real))"
  25.278 -by arith
  25.279 -
  25.280 -lemma "(-x \<le> -y) = (y \<le> (x::real))"
  25.281 -by arith
  25.282 -
  25.283 -lemma "(a + b) - (c + d) = (a - c) + (b - (d::real))"
  25.284 -by arith
  25.285 -
  25.286 -lemma "(0::real) - x = -x"
  25.287 -by arith
  25.288 -
  25.289 -lemma "x - (0::real) = x"
  25.290 -by arith
  25.291 -
  25.292 -lemma "w \<le> x \<and> y < z ==> w + y < x + (z::real)"
  25.293 -by arith
  25.294 -
  25.295 -lemma "w < x \<and> y \<le> z ==> w + y < x + (z::real)"
  25.296 -by arith
  25.297 -
  25.298 -lemma "(0::real) \<le> x \<and> 0 < y ==> 0 < x + (y::real)"
  25.299 -by arith
  25.300 -
  25.301 -lemma "(0::real) < x \<and> 0 \<le> y ==> 0 < x + y"
  25.302 -by arith
  25.303 -
  25.304 -lemma "-x - y = -(x + (y::real))"
  25.305 -by arith
  25.306 -
  25.307 -lemma "x - (-y) = x + (y::real)"
  25.308 -by arith
  25.309 -
  25.310 -lemma "-x - -y = y - (x::real)"
  25.311 -by arith
  25.312 -
  25.313 -lemma "(a - b) + (b - c) = a - (c::real)"
  25.314 -by arith
  25.315 -
  25.316 -lemma "(x = y - z) = (x + z = (y::real))"
  25.317 -by arith
  25.318 -
  25.319 -lemma "(x - y = z) = (x = z + (y::real))"
  25.320 -by arith
  25.321 -
  25.322 -lemma "x - (x - y) = (y::real)"
  25.323 -by arith
  25.324 -
  25.325 -lemma "x - (x + y) = -(y::real)"
  25.326 -by arith
  25.327 -
  25.328 -lemma "x = y ==> x \<le> (y::real)"
  25.329 -by arith
  25.330 -
  25.331 -lemma "(0::real) < x ==> \<not>(x = 0)"
  25.332 -by arith
  25.333 -
  25.334 -lemma "(x + y) * (x - y) = (x * x) - (y * y)"
  25.335 -  oops
  25.336 -
  25.337 -lemma "(-x = -y) = (x = (y::real))"
  25.338 -by arith
  25.339 -
  25.340 -lemma "(-x < -y) = (y < (x::real))"
  25.341 -by arith
  25.342 -
  25.343 -lemma "!!a::real. a \<le> b ==> c \<le> d ==> x + y < z ==> a + c \<le> b + d"
  25.344 -by (tactic "fast_arith_tac @{context} 1")
  25.345 -
  25.346 -lemma "!!a::real. a < b ==> c < d ==> a - d \<le> b + (-c)"
  25.347 -by (tactic "fast_arith_tac @{context} 1")
  25.348 -
  25.349 -lemma "!!a::real. a \<le> b ==> b + b \<le> c ==> a + a \<le> c"
  25.350 -by (tactic "fast_arith_tac @{context} 1")
  25.351 -
  25.352 -lemma "!!a::real. a + b \<le> i + j ==> a \<le> b ==> i \<le> j ==> a + a \<le> j + j"
  25.353 -by (tactic "fast_arith_tac @{context} 1")
  25.354 -
  25.355 -lemma "!!a::real. a + b < i + j ==> a < b ==> i < j ==> a + a < j + j"
  25.356 -by (tactic "fast_arith_tac @{context} 1")
  25.357 -
  25.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"
  25.359 -by arith
  25.360 -
  25.361 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  25.362 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a \<le> l"
  25.363 -by (tactic "fast_arith_tac @{context} 1")
  25.364 -
  25.365 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  25.366 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a + a + a + a \<le> l + l + l + l"
  25.367 -by (tactic "fast_arith_tac @{context} 1")
  25.368 -
  25.369 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  25.370 -    ==> c \<le> d ==> i \<le> j ==> j \<le> k ==> k \<le> l ==> a + a + a + a + a \<le> l + l + l + l + i"
  25.371 -by (tactic "fast_arith_tac @{context} 1")
  25.372 -
  25.373 -lemma "!!a::real. a + b + c + d \<le> i + j + k + l ==> a \<le> b ==> b \<le> c
  25.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"
  25.375 -by (tactic "fast_arith_tac @{context} 1")
  25.376 -
  25.377 -
  25.378 -subsection{*Complex Arithmetic*}
  25.379 -
  25.380 -lemma "(1359 + 93746*ii) - (2468 + 46375*ii) = -1109 + 47371*ii"
  25.381 -by simp
  25.382 -
  25.383 -lemma "- (65745 + -47371*ii) = -65745 + 47371*ii"
  25.384 -by simp
  25.385 -
  25.386 -text{*Multiplication requires distributive laws.  Perhaps versions instantiated
  25.387 -to literal constants should be added to the simpset.*}
  25.388 -
  25.389 -lemma "(1 + ii) * (1 - ii) = 2"
  25.390 -by (simp add: ring_distribs)
  25.391 -
  25.392 -lemma "(1 + 2*ii) * (1 + 3*ii) = -5 + 5*ii"
  25.393 -by (simp add: ring_distribs)
  25.394 -
  25.395 -lemma "(-84 + 255*ii) + (51 * 255*ii) = -84 + 13260 * ii"
  25.396 -by (simp add: ring_distribs)
  25.397 -
  25.398 -text{*No inequalities or linear arithmetic: the complex numbers are unordered!*}
  25.399 -
  25.400 -text{*No powers (not supported yet)*}
  25.401 -
  25.402 -end
    26.1 --- a/src/HOL/Complex/ex/HarmonicSeries.thy	Fri Dec 05 11:26:07 2008 +0100
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,323 +0,0 @@
    26.4 -(*  Title:      HOL/Library/HarmonicSeries.thy
    26.5 -    ID:         $Id$
    26.6 -    Author:     Benjamin Porter, 2006
    26.7 -*)
    26.8 -
    26.9 -header {* Divergence of the Harmonic Series *}
   26.10 -
   26.11 -theory HarmonicSeries
   26.12 -imports Complex_Main
   26.13 -begin
   26.14 -
   26.15 -section {* Abstract *}
   26.16 -
   26.17 -text {* The following document presents a proof of the Divergence of
   26.18 -Harmonic Series theorem formalised in the Isabelle/Isar theorem
   26.19 -proving system.
   26.20 -
   26.21 -{\em Theorem:} The series $\sum_{n=1}^{\infty} \frac{1}{n}$ does not
   26.22 -converge to any number.
   26.23 -
   26.24 -{\em Informal Proof:}
   26.25 -  The informal proof is based on the following auxillary lemmas:
   26.26 -  \begin{itemize}
   26.27 -  \item{aux: $\sum_{n=2^m-1}^{2^m} \frac{1}{n} \geq \frac{1}{2}$}
   26.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}$}
   26.29 -  \end{itemize}
   26.30 -
   26.31 -  From {\em aux} and {\em aux2} we can deduce that $\sum_{n=1}^{2^M}
   26.32 -  \frac{1}{n} \geq 1 + \frac{M}{2}$ for all $M$.
   26.33 -  Now for contradiction, assume that $\sum_{n=1}^{\infty} \frac{1}{n}
   26.34 -  = s$ for some $s$. Because $\forall n. \frac{1}{n} > 0$ all the
   26.35 -  partial sums in the series must be less than $s$. However with our
   26.36 -  deduction above we can choose $N > 2*s - 2$ and thus
   26.37 -  $\sum_{n=1}^{2^N} \frac{1}{n} > s$. This leads to a contradiction
   26.38 -  and hence $\sum_{n=1}^{\infty} \frac{1}{n}$ is not summable.
   26.39 -  QED.
   26.40 -*}
   26.41 -
   26.42 -section {* Formal Proof *}
   26.43 -
   26.44 -lemma two_pow_sub:
   26.45 -  "0 < m \<Longrightarrow> (2::nat)^m - 2^(m - 1) = 2^(m - 1)"
   26.46 -  by (induct m) auto
   26.47 -
   26.48 -text {* We first prove the following auxillary lemma. This lemma
   26.49 -simply states that the finite sums: $\frac{1}{2}$, $\frac{1}{3} +
   26.50 -\frac{1}{4}$, $\frac{1}{5} + \frac{1}{6} + \frac{1}{7} + \frac{1}{8}$
   26.51 -etc. are all greater than or equal to $\frac{1}{2}$. We do this by
   26.52 -observing that each term in the sum is greater than or equal to the
   26.53 -last term, e.g. $\frac{1}{3} > \frac{1}{4}$ and thus $\frac{1}{3} +
   26.54 -\frac{1}{4} > \frac{1}{4} + \frac{1}{4} = \frac{1}{2}$. *}
   26.55 -
   26.56 -lemma harmonic_aux:
   26.57 -  "\<forall>m>0. (\<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n) \<ge> 1/2"
   26.58 -  (is "\<forall>m>0. (\<Sum>n\<in>(?S m). 1/real n) \<ge> 1/2")
   26.59 -proof
   26.60 -  fix m::nat
   26.61 -  obtain tm where tmdef: "tm = (2::nat)^m" by simp
   26.62 -  {
   26.63 -    assume mgt0: "0 < m"
   26.64 -    have "\<And>x. x\<in>(?S m) \<Longrightarrow> 1/(real x) \<ge> 1/(real tm)"
   26.65 -    proof -
   26.66 -      fix x::nat
   26.67 -      assume xs: "x\<in>(?S m)"
   26.68 -      have xgt0: "x>0"
   26.69 -      proof -
   26.70 -        from xs have
   26.71 -          "x \<ge> 2^(m - 1) + 1" by auto
   26.72 -        moreover with mgt0 have
   26.73 -          "2^(m - 1) + 1 \<ge> (1::nat)" by auto
   26.74 -        ultimately have
   26.75 -          "x \<ge> 1" by (rule xtrans)
   26.76 -        thus ?thesis by simp
   26.77 -      qed
   26.78 -      moreover from xs have "x \<le> 2^m" by auto
   26.79 -      ultimately have
   26.80 -        "inverse (real x) \<ge> inverse (real ((2::nat)^m))" by simp
   26.81 -      moreover
   26.82 -      from xgt0 have "real x \<noteq> 0" by simp
   26.83 -      then have
   26.84 -        "inverse (real x) = 1 / (real x)"
   26.85 -        by (rule nonzero_inverse_eq_divide)
   26.86 -      moreover from mgt0 have "real tm \<noteq> 0" by (simp add: tmdef)
   26.87 -      then have
   26.88 -        "inverse (real tm) = 1 / (real tm)"
   26.89 -        by (rule nonzero_inverse_eq_divide)
   26.90 -      ultimately show
   26.91 -        "1/(real x) \<ge> 1/(real tm)" by (auto simp add: tmdef)
   26.92 -    qed
   26.93 -    then have
   26.94 -      "(\<Sum>n\<in>(?S m). 1 / real n) \<ge> (\<Sum>n\<in>(?S m). 1/(real tm))"
   26.95 -      by (rule setsum_mono)
   26.96 -    moreover have
   26.97 -      "(\<Sum>n\<in>(?S m). 1/(real tm)) = 1/2"
   26.98 -    proof -
   26.99 -      have
  26.100 -        "(\<Sum>n\<in>(?S m). 1/(real tm)) =
  26.101 -         (1/(real tm))*(\<Sum>n\<in>(?S m). 1)"
  26.102 -        by simp
  26.103 -      also have
  26.104 -        "\<dots> = ((1/(real tm)) * real (card (?S m)))"
  26.105 -        by (simp add: real_of_card real_of_nat_def)
  26.106 -      also have
  26.107 -        "\<dots> = ((1/(real tm)) * real (tm - (2^(m - 1))))"
  26.108 -        by (simp add: tmdef)
  26.109 -      also from mgt0 have
  26.110 -        "\<dots> = ((1/(real tm)) * real ((2::nat)^(m - 1)))"
  26.111 -        by (auto simp: tmdef dest: two_pow_sub)
  26.112 -      also have
  26.113 -        "\<dots> = (real (2::nat))^(m - 1) / (real (2::nat))^m"
  26.114 -        by (simp add: tmdef realpow_real_of_nat [symmetric])
  26.115 -      also from mgt0 have
  26.116 -        "\<dots> = (real (2::nat))^(m - 1) / (real (2::nat))^((m - 1) + 1)"
  26.117 -        by auto
  26.118 -      also have "\<dots> = 1/2" by simp
  26.119 -      finally show ?thesis .
  26.120 -    qed
  26.121 -    ultimately have
  26.122 -      "(\<Sum>n\<in>(?S m). 1 / real n) \<ge> 1/2"
  26.123 -      by - (erule subst)
  26.124 -  }
  26.125 -  thus "0 < m \<longrightarrow> 1 / 2 \<le> (\<Sum>n\<in>(?S m). 1 / real n)" by simp
  26.126 -qed
  26.127 -
  26.128 -text {* We then show that the sum of a finite number of terms from the
  26.129 -harmonic series can be regrouped in increasing powers of 2. For
  26.130 -example: $1 + \frac{1}{2} + \frac{1}{3} + \frac{1}{4} + \frac{1}{5} +
  26.131 -\frac{1}{6} + \frac{1}{7} + \frac{1}{8} = 1 + (\frac{1}{2}) +
  26.132 -(\frac{1}{3} + \frac{1}{4}) + (\frac{1}{5} + \frac{1}{6} + \frac{1}{7}
  26.133 -+ \frac{1}{8})$. *}
  26.134 -
  26.135 -lemma harmonic_aux2 [rule_format]:
  26.136 -  "0<M \<Longrightarrow> (\<Sum>n\<in>{1..(2::nat)^M}. 1/real n) =
  26.137 -   (1 + (\<Sum>m\<in>{1..M}. \<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n))"
  26.138 -  (is "0<M \<Longrightarrow> ?LHS M = ?RHS M")
  26.139 -proof (induct M)
  26.140 -  case 0 show ?case by simp
  26.141 -next
  26.142 -  case (Suc M)
  26.143 -  have ant: "0 < Suc M" by fact
  26.144 -  {
  26.145 -    have suc: "?LHS (Suc M) = ?RHS (Suc M)"
  26.146 -    proof cases -- "show that LHS = c and RHS = c, and thus LHS = RHS"
  26.147 -      assume mz: "M=0"
  26.148 -      {
  26.149 -        then have
  26.150 -          "?LHS (Suc M) = ?LHS 1" by simp
  26.151 -        also have
  26.152 -          "\<dots> = (\<Sum>n\<in>{(1::nat)..2}. 1/real n)" by simp
  26.153 -        also have
  26.154 -          "\<dots> = ((\<Sum>n\<in>{Suc 1..2}. 1/real n) + 1/(real (1::nat)))"
  26.155 -          by (subst setsum_head)
  26.156 -             (auto simp: atLeastSucAtMost_greaterThanAtMost)
  26.157 -        also have
  26.158 -          "\<dots> = ((\<Sum>n\<in>{2..2::nat}. 1/real n) + 1/(real (1::nat)))"
  26.159 -          by (simp add: nat_number)
  26.160 -        also have
  26.161 -          "\<dots> =  1/(real (2::nat)) + 1/(real (1::nat))" by simp
  26.162 -        finally have
  26.163 -          "?LHS (Suc M) = 1/2 + 1" by simp
  26.164 -      }
  26.165 -      moreover
  26.166 -      {
  26.167 -        from mz have
  26.168 -          "?RHS (Suc M) = ?RHS 1" by simp
  26.169 -        also have
  26.170 -          "\<dots> = (\<Sum>n\<in>{((2::nat)^0)+1..2^1}. 1/real n) + 1"
  26.171 -          by simp
  26.172 -        also have
  26.173 -          "\<dots> = (\<Sum>n\<in>{2::nat..2}. 1/real n) + 1"
  26.174 -        proof -
  26.175 -          have "(2::nat)^0 = 1" by simp
  26.176 -          then have "(2::nat)^0+1 = 2" by simp
  26.177 -          moreover have "(2::nat)^1 = 2" by simp
  26.178 -          ultimately have "{((2::nat)^0)+1..2^1} = {2::nat..2}" by auto
  26.179 -          thus ?thesis by simp
  26.180 -        qed
  26.181 -        also have
  26.182 -          "\<dots> = 1/2 + 1"
  26.183 -          by simp
  26.184 -        finally have
  26.185 -          "?RHS (Suc M) = 1/2 + 1" by simp
  26.186 -      }
  26.187 -      ultimately show "?LHS (Suc M) = ?RHS (Suc M)" by simp
  26.188 -    next
  26.189 -      assume mnz: "M\<noteq>0"
  26.190 -      then have mgtz: "M>0" by simp
  26.191 -      with Suc have suc:
  26.192 -        "(?LHS M) = (?RHS M)" by blast
  26.193 -      have
  26.194 -        "(?LHS (Suc M)) =
  26.195 -         ((?LHS M) + (\<Sum>n\<in>{(2::nat)^M+1..2^(Suc M)}. 1 / real n))"
  26.196 -      proof -
  26.197 -        have
  26.198 -          "{1..(2::nat)^(Suc M)} =
  26.199 -           {1..(2::nat)^M}\<union>{(2::nat)^M+1..(2::nat)^(Suc M)}"
  26.200 -          by auto
  26.201 -        moreover have
  26.202 -          "{1..(2::nat)^M}\<inter>{(2::nat)^M+1..(2::nat)^(Suc M)} = {}"
  26.203 -          by auto
  26.204 -        moreover have
  26.205 -          "finite {1..(2::nat)^M}" and "finite {(2::nat)^M+1..(2::nat)^(Suc M)}"
  26.206 -          by auto
  26.207 -        ultimately show ?thesis
  26.208 -          by (auto intro: setsum_Un_disjoint)
  26.209 -      qed
  26.210 -      moreover
  26.211 -      {
  26.212 -        have
  26.213 -          "(?RHS (Suc M)) =
  26.214 -           (1 + (\<Sum>m\<in>{1..M}.  \<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n) +
  26.215 -           (\<Sum>n\<in>{(2::nat)^(Suc M - 1)+1..2^(Suc M)}. 1/real n))" by simp
  26.216 -        also have
  26.217 -          "\<dots> = (?RHS M) + (\<Sum>n\<in>{(2::nat)^M+1..2^(Suc M)}. 1/real n)"
  26.218 -          by simp
  26.219 -        also from suc have
  26.220 -          "\<dots> = (?LHS M) +  (\<Sum>n\<in>{(2::nat)^M+1..2^(Suc M)}. 1/real n)"
  26.221 -          by simp
  26.222 -        finally have
  26.223 -          "(?RHS (Suc M)) = \<dots>" by simp
  26.224 -      }
  26.225 -      ultimately show "?LHS (Suc M) = ?RHS (Suc M)" by simp
  26.226 -    qed
  26.227 -  }
  26.228 -  thus ?case by simp
  26.229 -qed
  26.230 -
  26.231 -text {* Using @{thm [source] harmonic_aux} and @{thm [source] harmonic_aux2} we now show
  26.232 -that each group sum is greater than or equal to $\frac{1}{2}$ and thus
  26.233 -the finite sum is bounded below by a value proportional to the number
  26.234 -of elements we choose. *}
  26.235 -
  26.236 -lemma harmonic_aux3 [rule_format]:
  26.237 -  shows "\<forall>(M::nat). (\<Sum>n\<in>{1..(2::nat)^M}. 1 / real n) \<ge> 1 + (real M)/2"
  26.238 -  (is "\<forall>M. ?P M \<ge> _")
  26.239 -proof (rule allI, cases)
  26.240 -  fix M::nat
  26.241 -  assume "M=0"
  26.242 -  then show "?P M \<ge> 1 + (real M)/2" by simp
  26.243 -next
  26.244 -  fix M::nat
  26.245 -  assume "M\<noteq>0"
  26.246 -  then have "M > 0" by simp
  26.247 -  then have
  26.248 -    "(?P M) =
  26.249 -     (1 + (\<Sum>m\<in>{1..M}. \<Sum>n\<in>{(2::nat)^(m - 1)+1..2^m}. 1/real n))"
  26.250 -    by (rule harmonic_aux2)
  26.251 -  also have
  26.252 -    "\<dots> \<ge> (1 + (\<Sum>m\<in>{1..M}. 1/2))"
  26.253 -  proof -
  26.254 -    let ?f = "(\<lambda>x. 1/2)"
  26.255 -    let ?g = "(\<lambda>x. (\<Sum>n\<in>{(2::nat)^(x - 1)+1..2^x}. 1/real n))"
  26.256 -    from harmonic_aux have "\<And>x. x\<in>{1..M} \<Longrightarrow> ?f x \<le> ?g x" by simp
  26.257 -    then have "(\<Sum>m\<in>{1..M}. ?g m) \<ge> (\<Sum>m\<in>{1..M}. ?f m)" by (rule setsum_mono)
  26.258 -    thus ?thesis by simp
  26.259 -  qed
  26.260 -  finally have "(?P M) \<ge> (1 + (\<Sum>m\<in>{1..M}. 1/2))" .
  26.261 -  moreover
  26.262 -  {
  26.263 -    have
  26.264 -      "(\<Sum>m\<in>{1..M}. (1::real)/2) = 1/2 * (\<Sum>m\<in>{1..M}. 1)"
  26.265 -      by auto
  26.266 -    also have
  26.267 -      "\<dots> = 1/2*(real (card {1..M}))"
  26.268 -      by (simp only: real_of_card[symmetric])
  26.269 -    also have
  26.270 -      "\<dots> = 1/2*(real M)" by simp
  26.271 -    also have
  26.272 -      "\<dots> = (real M)/2" by simp
  26.273 -    finally have "(\<Sum>m\<in>{1..M}. (1::real)/2) = (real M)/2" .
  26.274 -  }
  26.275 -  ultimately show "(?P M) \<ge> (1 + (real M)/2)" by simp
  26.276 -qed
  26.277 -
  26.278 -text {* The final theorem shows that as we take more and more elements
  26.279 -(see @{thm [source] harmonic_aux3}) we get an ever increasing sum. By assuming
  26.280 -the sum converges, the lemma @{thm [source] series_pos_less} ( @{thm
  26.281 -series_pos_less} ) states that each sum is bounded above by the
  26.282 -series' limit. This contradicts our first statement and thus we prove
  26.283 -that the harmonic series is divergent. *}
  26.284 -
  26.285 -theorem DivergenceOfHarmonicSeries:
  26.286 -  shows "\<not>summable (\<lambda>n. 1/real (Suc n))"
  26.287 -  (is "\<not>summable ?f")
  26.288 -proof -- "by contradiction"
  26.289 -  let ?s = "suminf ?f" -- "let ?s equal the sum of the harmonic series"
  26.290 -  assume sf: "summable ?f"
  26.291 -  then obtain n::nat where ndef: "n = nat \<lceil>2 * ?s\<rceil>" by simp
  26.292 -  then have ngt: "1 + real n/2 > ?s"
  26.293 -  proof -
  26.294 -    have "\<forall>n. 0 \<le> ?f n" by simp
  26.295 -    with sf have "?s \<ge> 0"
  26.296 -      by - (rule suminf_0_le, simp_all)
  26.297 -    then have cgt0: "\<lceil>2*?s\<rceil> \<ge> 0" by simp
  26.298 -
  26.299 -    from ndef have "n = nat \<lceil>(2*?s)\<rceil>" .
  26.300 -    then have "real n = real (nat \<lceil>2*?s\<rceil>)" by simp
  26.301 -    with cgt0 have "real n = real \<lceil>2*?s\<rceil>"
  26.302 -      by (auto dest: real_nat_eq_real)
  26.303 -    then have "real n \<ge> 2*(?s)" by simp
  26.304 -    then have "real n/2 \<ge> (?s)" by simp
  26.305 -    then show "1 + real n/2 > (?s)" by simp
  26.306 -  qed
  26.307 -
  26.308 -  obtain j where jdef: "j = (2::nat)^n" by simp
  26.309 -  have "\<forall>m\<ge>j. 0 < ?f m" by simp
  26.310 -  with sf have "(\<Sum>i\<in>{0..<j}. ?f i) < ?s" by (rule series_pos_less)
  26.311 -  then have "(\<Sum>i\<in>{1..<Suc j}. 1/(real i)) < ?s"
  26.312 -    apply -
  26.313 -    apply (subst(asm) setsum_shift_bounds_Suc_ivl [symmetric])
  26.314 -    by simp
  26.315 -  with jdef have
  26.316 -    "(\<Sum>i\<in>{1..< Suc ((2::nat)^n)}. 1 / (real i)) < ?s" by simp
  26.317 -  then have
  26.318 -    "(\<Sum>i\<in>{1..(2::nat)^n}. 1 / (real i)) < ?s"
  26.319 -    by (simp only: atLeastLessThanSuc_atLeastAtMost)
  26.320 -  moreover from harmonic_aux3 have
  26.321 -    "(\<Sum>i\<in>{1..(2::nat)^n}. 1 / (real i)) \<ge> 1 + real n/2" by simp
  26.322 -  moreover from ngt have "1 + real n/2 > ?s" by simp
  26.323 -  ultimately show False by simp
  26.324 -qed
  26.325 -
  26.326 -end
  26.327 \ No newline at end of file
    27.1 --- a/src/HOL/Complex/ex/MIR.thy	Fri Dec 05 11:26:07 2008 +0100
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,5933 +0,0 @@
    27.4 -(*  Title:      Complex/ex/MIR.thy
    27.5 -    Author:     Amine Chaieb
    27.6 -*)
    27.7 -
    27.8 -theory MIR
    27.9 -imports List Real Code_Integer Efficient_Nat
   27.10 -uses ("mirtac.ML")
   27.11 -begin
   27.12 -
   27.13 -section {* Quantifier elimination for @{text "\<real> (0, 1, +, floor, <)"} *}
   27.14 -
   27.15 -declare real_of_int_floor_cancel [simp del]
   27.16 -
   27.17 -primrec alluopairs:: "'a list \<Rightarrow> ('a \<times> 'a) list" where 
   27.18 -  "alluopairs [] = []"
   27.19 -| "alluopairs (x#xs) = (map (Pair x) (x#xs))@(alluopairs xs)"
   27.20 -
   27.21 -lemma alluopairs_set1: "set (alluopairs xs) \<le> {(x,y). x\<in> set xs \<and> y\<in> set xs}"
   27.22 -by (induct xs, auto)
   27.23 -
   27.24 -lemma alluopairs_set:
   27.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) "
   27.26 -by (induct xs, auto)
   27.27 -
   27.28 -lemma alluopairs_ex:
   27.29 -  assumes Pc: "\<forall> x y. P x y = P y x"
   27.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)"
   27.31 -proof
   27.32 -  assume "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y"
   27.33 -  then obtain x y where x: "x \<in> set xs" and y:"y \<in> set xs" and P: "P x y"  by blast
   27.34 -  from alluopairs_set[OF x y] P Pc show"\<exists>(x, y)\<in>set (alluopairs xs). P x y" 
   27.35 -    by auto
   27.36 -next
   27.37 -  assume "\<exists>(x, y)\<in>set (alluopairs xs). P x y"
   27.38 -  then obtain "x" and "y"  where xy:"(x,y) \<in> set (alluopairs xs)" and P: "P x y" by blast+
   27.39 -  from xy have "x \<in> set xs \<and> y\<in> set xs" using alluopairs_set1 by blast
   27.40 -  with P show "\<exists>x\<in>set xs. \<exists>y\<in>set xs. P x y" by blast
   27.41 -qed
   27.42 -
   27.43 -  (* generate a list from i to j*)
   27.44 -consts iupt :: "int \<times> int \<Rightarrow> int list"
   27.45 -recdef iupt "measure (\<lambda> (i,j). nat (j-i +1))" 
   27.46 -  "iupt (i,j) = (if j <i then [] else (i# iupt(i+1, j)))"
   27.47 -
   27.48 -lemma iupt_set: "set (iupt(i,j)) = {i .. j}"
   27.49 -proof(induct rule: iupt.induct)
   27.50 -  case (1 a b)
   27.51 -  show ?case
   27.52 -    using prems by (simp add: simp_from_to)
   27.53 -qed
   27.54 -
   27.55 -lemma nth_pos2: "0 < n \<Longrightarrow> (x#xs) ! n = xs ! (n - 1)"
   27.56 -using Nat.gr0_conv_Suc
   27.57 -by clarsimp
   27.58 -
   27.59 -
   27.60 -lemma myl: "\<forall> (a::'a::{pordered_ab_group_add}) (b::'a). (a \<le> b) = (0 \<le> b - a)" 
   27.61 -proof(clarify)
   27.62 -  fix x y ::"'a"
   27.63 -  have "(x \<le> y) = (x - y \<le> 0)" by (simp only: le_iff_diff_le_0[where a="x" and b="y"])
   27.64 -  also have "\<dots> = (- (y - x) \<le> 0)" by simp
   27.65 -  also have "\<dots> = (0 \<le> y - x)" by (simp only: neg_le_0_iff_le[where a="y-x"])
   27.66 -  finally show "(x \<le> y) = (0 \<le> y - x)" .
   27.67 -qed
   27.68 -
   27.69 -lemma myless: "\<forall> (a::'a::{pordered_ab_group_add}) (b::'a). (a < b) = (0 < b - a)" 
   27.70 -proof(clarify)
   27.71 -  fix x y ::"'a"
   27.72 -  have "(x < y) = (x - y < 0)" by (simp only: less_iff_diff_less_0[where a="x" and b="y"])
   27.73 -  also have "\<dots> = (- (y - x) < 0)" by simp
   27.74 -  also have "\<dots> = (0 < y - x)" by (simp only: neg_less_0_iff_less[where a="y-x"])
   27.75 -  finally show "(x < y) = (0 < y - x)" .
   27.76 -qed
   27.77 -
   27.78 -lemma myeq: "\<forall> (a::'a::{pordered_ab_group_add}) (b::'a). (a = b) = (0 = b - a)"
   27.79 -  by auto
   27.80 -
   27.81 -  (* Maybe should be added to the library \<dots> *)
   27.82 -lemma floor_int_eq: "(real n\<le> x \<and> x < real (n+1)) = (floor x = n)"
   27.83 -proof( auto)
   27.84 -  assume lb: "real n \<le> x"
   27.85 -    and ub: "x < real n + 1"
   27.86 -  have "real (floor x) \<le> x" by simp 
   27.87 -  hence "real (floor x) < real (n + 1) " using ub by arith
   27.88 -  hence "floor x < n+1" by simp
   27.89 -  moreover from lb have "n \<le> floor x" using floor_mono2[where x="real n" and y="x"] 
   27.90 -    by simp ultimately show "floor x = n" by simp
   27.91 -qed
   27.92 -
   27.93 -(* Periodicity of dvd *)
   27.94 -lemma dvd_period:
   27.95 -  assumes advdd: "(a::int) dvd d"
   27.96 -  shows "(a dvd (x + t)) = (a dvd ((x+ c*d) + t))"
   27.97 -  using advdd  
   27.98 -proof-
   27.99 -  {fix x k
  27.100 -    from inf_period(3)[OF advdd, rule_format, where x=x and k="-k"]  
  27.101 -    have " ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))" by simp}
  27.102 -  hence "\<forall>x.\<forall>k. ((a::int) dvd (x + t)) = (a dvd (x+k*d + t))"  by simp
  27.103 -  then show ?thesis by simp
  27.104 -qed
  27.105 -
  27.106 -  (* The Divisibility relation between reals *)	
  27.107 -definition
  27.108 -  rdvd:: "real \<Rightarrow> real \<Rightarrow> bool" (infixl "rdvd" 50)
  27.109 -where
  27.110 -  rdvd_def: "x rdvd y \<longleftrightarrow> (\<exists>k\<Colon>int. y = x * real k)"
  27.111 -
  27.112 -lemma int_rdvd_real: 
  27.113 -  shows "real (i::int) rdvd x = (i dvd (floor x) \<and> real (floor x) = x)" (is "?l = ?r")
  27.114 -proof
  27.115 -  assume "?l" 
  27.116 -  hence th: "\<exists> k. x=real (i*k)" by (simp add: rdvd_def)
  27.117 -  hence th': "real (floor x) = x" by (auto simp del: real_of_int_mult)
  27.118 -  with th have "\<exists> k. real (floor x) = real (i*k)" by simp
  27.119 -  hence "\<exists> k. floor x = i*k" by (simp only: real_of_int_inject)
  27.120 -  thus ?r  using th' by (simp add: dvd_def) 
  27.121 -next
  27.122 -  assume "?r" hence "(i\<Colon>int) dvd \<lfloor>x\<Colon>real\<rfloor>" ..
  27.123 -  hence "\<exists> k. real (floor x) = real (i*k)" 
  27.124 -    by (simp only: real_of_int_inject) (simp add: dvd_def)
  27.125 -  thus ?l using prems by (simp add: rdvd_def)
  27.126 -qed
  27.127 -
  27.128 -lemma int_rdvd_iff: "(real (i::int) rdvd real t) = (i dvd t)"
  27.129 -by (auto simp add: rdvd_def dvd_def) (rule_tac x="k" in exI, simp only :real_of_int_mult[symmetric])
  27.130 -
  27.131 -
  27.132 -lemma rdvd_abs1: 
  27.133 -  "(abs (real d) rdvd t) = (real (d ::int) rdvd t)"
  27.134 -proof
  27.135 -  assume d: "real d rdvd t"
  27.136 -  from d int_rdvd_real have d2: "d dvd (floor t)" and ti: "real (floor t) = t" by auto
  27.137 -
  27.138 -  from iffD2[OF zdvd_abs1] d2 have "(abs d) dvd (floor t)" by blast
  27.139 -  with ti int_rdvd_real[symmetric] have "real (abs d) rdvd t" by blast 
  27.140 -  thus "abs (real d) rdvd t" by simp
  27.141 -next
  27.142 -  assume "abs (real d) rdvd t" hence "real (abs d) rdvd t" by simp
  27.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
  27.144 -  from iffD1[OF zdvd_abs1] d2 have "d dvd floor t" by blast
  27.145 -  with ti int_rdvd_real[symmetric] show "real d rdvd t" by blast
  27.146 -qed
  27.147 -
  27.148 -lemma rdvd_minus: "(real (d::int) rdvd t) = (real d rdvd -t)"
  27.149 -  apply (auto simp add: rdvd_def)
  27.150 -  apply (rule_tac x="-k" in exI, simp) 
  27.151 -  apply (rule_tac x="-k" in exI, simp)
  27.152 -done
  27.153 -
  27.154 -lemma rdvd_left_0_eq: "(0 rdvd t) = (t=0)"
  27.155 -by (auto simp add: rdvd_def)
  27.156 -
  27.157 -lemma rdvd_mult: 
  27.158 -  assumes knz: "k\<noteq>0"
  27.159 -  shows "(real (n::int) * real (k::int) rdvd x * real k) = (real n rdvd x)"
  27.160 -using knz by (simp add:rdvd_def)
  27.161 -
  27.162 -lemma rdvd_trans: assumes mn:"m rdvd n" and  nk:"n rdvd k" 
  27.163 -  shows "m rdvd k"
  27.164 -proof-
  27.165 -  from rdvd_def mn obtain c where nmc:"n = m * real (c::int)" by auto
  27.166 -  from rdvd_def nk obtain c' where nkc:"k = n * real (c'::int)" by auto
  27.167 -  hence "k = m * real (c * c')" using nmc by simp
  27.168 -  thus ?thesis using rdvd_def by blast
  27.169 -qed
  27.170 -
  27.171 -  (*********************************************************************************)
  27.172 -  (****                            SHADOW SYNTAX AND SEMANTICS                  ****)
  27.173 -  (*********************************************************************************)
  27.174 -
  27.175 -datatype num = C int | Bound nat | CN nat int num | Neg num | Add num num| Sub num num 
  27.176 -  | Mul int num | Floor num| CF int num num
  27.177 -
  27.178 -  (* A size for num to make inductive proofs simpler*)
  27.179 -primrec num_size :: "num \<Rightarrow> nat" where
  27.180 - "num_size (C c) = 1"
  27.181 -| "num_size (Bound n) = 1"
  27.182 -| "num_size (Neg a) = 1 + num_size a"
  27.183 -| "num_size (Add a b) = 1 + num_size a + num_size b"
  27.184 -| "num_size (Sub a b) = 3 + num_size a + num_size b"
  27.185 -| "num_size (CN n c a) = 4 + num_size a "
  27.186 -| "num_size (CF c a b) = 4 + num_size a + num_size b"
  27.187 -| "num_size (Mul c a) = 1 + num_size a"
  27.188 -| "num_size (Floor a) = 1 + num_size a"
  27.189 -
  27.190 -  (* Semantics of numeral terms (num) *)
  27.191 -primrec Inum :: "real list \<Rightarrow> num \<Rightarrow> real" where
  27.192 -  "Inum bs (C c) = (real c)"
  27.193 -| "Inum bs (Bound n) = bs!n"
  27.194 -| "Inum bs (CN n c a) = (real c) * (bs!n) + (Inum bs a)"
  27.195 -| "Inum bs (Neg a) = -(Inum bs a)"
  27.196 -| "Inum bs (Add a b) = Inum bs a + Inum bs b"
  27.197 -| "Inum bs (Sub a b) = Inum bs a - Inum bs b"
  27.198 -| "Inum bs (Mul c a) = (real c) * Inum bs a"
  27.199 -| "Inum bs (Floor a) = real (floor (Inum bs a))"
  27.200 -| "Inum bs (CF c a b) = real c * real (floor (Inum bs a)) + Inum bs b"
  27.201 -definition "isint t bs \<equiv> real (floor (Inum bs t)) = Inum bs t"
  27.202 -
  27.203 -lemma isint_iff: "isint n bs = (real (floor (Inum bs n)) = Inum bs n)"
  27.204 -by (simp add: isint_def)
  27.205 -
  27.206 -lemma isint_Floor: "isint (Floor n) bs"
  27.207 -  by (simp add: isint_iff)
  27.208 -
  27.209 -lemma isint_Mul: "isint e bs \<Longrightarrow> isint (Mul c e) bs"
  27.210 -proof-
  27.211 -  let ?e = "Inum bs e"
  27.212 -  let ?fe = "floor ?e"
  27.213 -  assume be: "isint e bs" hence efe:"real ?fe = ?e" by (simp add: isint_iff)
  27.214 -  have "real ((floor (Inum bs (Mul c e)))) = real (floor (real (c * ?fe)))" using efe by simp
  27.215 -  also have "\<dots> = real (c* ?fe)" by (simp only: floor_real_of_int) 
  27.216 -  also have "\<dots> = real c * ?e" using efe by simp
  27.217 -  finally show ?thesis using isint_iff by simp
  27.218 -qed
  27.219 -
  27.220 -lemma isint_neg: "isint e bs \<Longrightarrow> isint (Neg e) bs"
  27.221 -proof-
  27.222 -  let ?I = "\<lambda> t. Inum bs t"
  27.223 -  assume ie: "isint e bs"
  27.224 -  hence th: "real (floor (?I e)) = ?I e" by (simp add: isint_def)  
  27.225 -  have "real (floor (?I (Neg e))) = real (floor (- (real (floor (?I e)))))" by (simp add: th)
  27.226 -  also have "\<dots> = - real (floor (?I e))" by(simp add: floor_minus_real_of_int) 
  27.227 -  finally show "isint (Neg e) bs" by (simp add: isint_def th)
  27.228 -qed
  27.229 -
  27.230 -lemma isint_sub: 
  27.231 -  assumes ie: "isint e bs" shows "isint (Sub (C c) e) bs"
  27.232 -proof-
  27.233 -  let ?I = "\<lambda> t. Inum bs t"
  27.234 -  from ie have th: "real (floor (?I e)) = ?I e" by (simp add: isint_def)  
  27.235 -  have "real (floor (?I (Sub (C c) e))) = real (floor ((real (c -floor (?I e)))))" by (simp add: th)
  27.236 -  also have "\<dots> = real (c- floor (?I e))" by(simp add: floor_minus_real_of_int) 
  27.237 -  finally show "isint (Sub (C c) e) bs" by (simp add: isint_def th)
  27.238 -qed
  27.239 -
  27.240 -lemma isint_add: assumes
  27.241 -  ai:"isint a bs" and bi: "isint b bs" shows "isint (Add a b) bs"
  27.242 -proof-
  27.243 -  let ?a = "Inum bs a"
  27.244 -  let ?b = "Inum bs b"
  27.245 -  from ai bi isint_iff have "real (floor (?a + ?b)) = real (floor (real (floor ?a) + real (floor ?b)))" by simp
  27.246 -  also have "\<dots> = real (floor ?a) + real (floor ?b)" by simp
  27.247 -  also have "\<dots> = ?a + ?b" using ai bi isint_iff by simp
  27.248 -  finally show "isint (Add a b) bs" by (simp add: isint_iff)
  27.249 -qed
  27.250 -
  27.251 -lemma isint_c: "isint (C j) bs"
  27.252 -  by (simp add: isint_iff)
  27.253 -
  27.254 -
  27.255 -    (* FORMULAE *)
  27.256 -datatype fm  = 
  27.257 -  T| F| Lt num| Le num| Gt num| Ge num| Eq num| NEq num| Dvd int num| NDvd int num|
  27.258 -  NOT fm| And fm fm|  Or fm fm| Imp fm fm| Iff fm fm| E fm| A fm
  27.259 -
  27.260 -
  27.261 -  (* A size for fm *)
  27.262 -fun fmsize :: "fm \<Rightarrow> nat" where
  27.263 - "fmsize (NOT p) = 1 + fmsize p"
  27.264 -| "fmsize (And p q) = 1 + fmsize p + fmsize q"
  27.265 -| "fmsize (Or p q) = 1 + fmsize p + fmsize q"
  27.266 -| "fmsize (Imp p q) = 3 + fmsize p + fmsize q"
  27.267 -| "fmsize (Iff p q) = 3 + 2*(fmsize p + fmsize q)"
  27.268 -| "fmsize (E p) = 1 + fmsize p"
  27.269 -| "fmsize (A p) = 4+ fmsize p"
  27.270 -| "fmsize (Dvd i t) = 2"
  27.271 -| "fmsize (NDvd i t) = 2"
  27.272 -| "fmsize p = 1"
  27.273 -  (* several lemmas about fmsize *)
  27.274 -lemma fmsize_pos: "fmsize p > 0"	
  27.275 -by (induct p rule: fmsize.induct) simp_all
  27.276 -
  27.277 -  (* Semantics of formulae (fm) *)
  27.278 -primrec Ifm ::"real list \<Rightarrow> fm \<Rightarrow> bool" where
  27.279 -  "Ifm bs T = True"
  27.280 -| "Ifm bs F = False"
  27.281 -| "Ifm bs (Lt a) = (Inum bs a < 0)"
  27.282 -| "Ifm bs (Gt a) = (Inum bs a > 0)"
  27.283 -| "Ifm bs (Le a) = (Inum bs a \<le> 0)"
  27.284 -| "Ifm bs (Ge a) = (Inum bs a \<ge> 0)"
  27.285 -| "Ifm bs (Eq a) = (Inum bs a = 0)"
  27.286 -| "Ifm bs (NEq a) = (Inum bs a \<noteq> 0)"
  27.287 -| "Ifm bs (Dvd i b) = (real i rdvd Inum bs b)"
  27.288 -| "Ifm bs (NDvd i b) = (\<not>(real i rdvd Inum bs b))"
  27.289 -| "Ifm bs (NOT p) = (\<not> (Ifm bs p))"
  27.290 -| "Ifm bs (And p q) = (Ifm bs p \<and> Ifm bs q)"
  27.291 -| "Ifm bs (Or p q) = (Ifm bs p \<or> Ifm bs q)"
  27.292 -| "Ifm bs (Imp p q) = ((Ifm bs p) \<longrightarrow> (Ifm bs q))"
  27.293 -| "Ifm bs (Iff p q) = (Ifm bs p = Ifm bs q)"
  27.294 -| "Ifm bs (E p) = (\<exists> x. Ifm (x#bs) p)"
  27.295 -| "Ifm bs (A p) = (\<forall> x. Ifm (x#bs) p)"
  27.296 -
  27.297 -consts prep :: "fm \<Rightarrow> fm"
  27.298 -recdef prep "measure fmsize"
  27.299 -  "prep (E T) = T"
  27.300 -  "prep (E F) = F"
  27.301 -  "prep (E (Or p q)) = Or (prep (E p)) (prep (E q))"
  27.302 -  "prep (E (Imp p q)) = Or (prep (E (NOT p))) (prep (E q))"
  27.303 -  "prep (E (Iff p q)) = Or (prep (E (And p q))) (prep (E (And (NOT p) (NOT q))))" 
  27.304 -  "prep (E (NOT (And p q))) = Or (prep (E (NOT p))) (prep (E(NOT q)))"
  27.305 -  "prep (E (NOT (Imp p q))) = prep (E (And p (NOT q)))"
  27.306 -  "prep (E (NOT (Iff p q))) = Or (prep (E (And p (NOT q)))) (prep (E(And (NOT p) q)))"
  27.307 -  "prep (E p) = E (prep p)"
  27.308 -  "prep (A (And p q)) = And (prep (A p)) (prep (A q))"
  27.309 -  "prep (A p) = prep (NOT (E (NOT p)))"
  27.310 -  "prep (NOT (NOT p)) = prep p"
  27.311 -  "prep (NOT (And p q)) = Or (prep (NOT p)) (prep (NOT q))"
  27.312 -  "prep (NOT (A p)) = prep (E (NOT p))"
  27.313 -  "prep (NOT (Or p q)) = And (prep (NOT p)) (prep (NOT q))"
  27.314 -  "prep (NOT (Imp p q)) = And (prep p) (prep (NOT q))"
  27.315 -  "prep (NOT (Iff p q)) = Or (prep (And p (NOT q))) (prep (And (NOT p) q))"
  27.316 -  "prep (NOT p) = NOT (prep p)"
  27.317 -  "prep (Or p q) = Or (prep p) (prep q)"
  27.318 -  "prep (And p q) = And (prep p) (prep q)"
  27.319 -  "prep (Imp p q) = prep (Or (NOT p) q)"
  27.320 -  "prep (Iff p q) = Or (prep (And p q)) (prep (And (NOT p) (NOT q)))"
  27.321 -  "prep p = p"
  27.322 -(hints simp add: fmsize_pos)
  27.323 -lemma prep: "\<And> bs. Ifm bs (prep p) = Ifm bs p"
  27.324 -by (induct p rule: prep.induct, auto)
  27.325 -
  27.326 -
  27.327 -  (* Quantifier freeness *)
  27.328 -fun qfree:: "fm \<Rightarrow> bool" where
  27.329 -  "qfree (E p) = False"
  27.330 -  | "qfree (A p) = False"
  27.331 -  | "qfree (NOT p) = qfree p" 
  27.332 -  | "qfree (And p q) = (qfree p \<and> qfree q)" 
  27.333 -  | "qfree (Or  p q) = (qfree p \<and> qfree q)" 
  27.334 -  | "qfree (Imp p q) = (qfree p \<and> qfree q)" 
  27.335 -  | "qfree (Iff p q) = (qfree p \<and> qfree q)"
  27.336 -  | "qfree p = True"
  27.337 -
  27.338 -  (* Boundedness and substitution *)
  27.339 -primrec numbound0 :: "num \<Rightarrow> bool" (* a num is INDEPENDENT of Bound 0 *) where
  27.340 -  "numbound0 (C c) = True"
  27.341 -  | "numbound0 (Bound n) = (n>0)"
  27.342 -  | "numbound0 (CN n i a) = (n > 0 \<and> numbound0 a)"
  27.343 -  | "numbound0 (Neg a) = numbound0 a"
  27.344 -  | "numbound0 (Add a b) = (numbound0 a \<and> numbound0 b)"
  27.345 -  | "numbound0 (Sub a b) = (numbound0 a \<and> numbound0 b)" 
  27.346 -  | "numbound0 (Mul i a) = numbound0 a"
  27.347 -  | "numbound0 (Floor a) = numbound0 a"
  27.348 -  | "numbound0 (CF c a b) = (numbound0 a \<and> numbound0 b)" 
  27.349 -
  27.350 -lemma numbound0_I:
  27.351 -  assumes nb: "numbound0 a"
  27.352 -  shows "Inum (b#bs) a = Inum (b'#bs) a"
  27.353 -  using nb by (induct a) (auto simp add: nth_pos2)
  27.354 -
  27.355 -lemma numbound0_gen: 
  27.356 -  assumes nb: "numbound0 t" and ti: "isint t (x#bs)"
  27.357 -  shows "\<forall> y. isint t (y#bs)"
  27.358 -using nb ti 
  27.359 -proof(clarify)
  27.360 -  fix y
  27.361 -  from numbound0_I[OF nb, where bs="bs" and b="y" and b'="x"] ti[simplified isint_def]
  27.362 -  show "isint t (y#bs)"
  27.363 -    by (simp add: isint_def)
  27.364 -qed
  27.365 -
  27.366 -primrec bound0:: "fm \<Rightarrow> bool" (* A Formula is independent of Bound 0 *) where
  27.367 -  "bound0 T = True"
  27.368 -  | "bound0 F = True"
  27.369 -  | "bound0 (Lt a) = numbound0 a"
  27.370 -  | "bound0 (Le a) = numbound0 a"
  27.371 -  | "bound0 (Gt a) = numbound0 a"
  27.372 -  | "bound0 (Ge a) = numbound0 a"
  27.373 -  | "bound0 (Eq a) = numbound0 a"
  27.374 -  | "bound0 (NEq a) = numbound0 a"
  27.375 -  | "bound0 (Dvd i a) = numbound0 a"
  27.376 -  | "bound0 (NDvd i a) = numbound0 a"
  27.377 -  | "bound0 (NOT p) = bound0 p"
  27.378 -  | "bound0 (And p q) = (bound0 p \<and> bound0 q)"
  27.379 -  | "bound0 (Or p q) = (bound0 p \<and> bound0 q)"
  27.380 -  | "bound0 (Imp p q) = ((bound0 p) \<and> (bound0 q))"
  27.381 -  | "bound0 (Iff p q) = (bound0 p \<and> bound0 q)"
  27.382 -  | "bound0 (E p) = False"
  27.383 -  | "bound0 (A p) = False"
  27.384 -
  27.385 -lemma bound0_I:
  27.386 -  assumes bp: "bound0 p"
  27.387 -  shows "Ifm (b#bs) p = Ifm (b'#bs) p"
  27.388 - using bp numbound0_I [where b="b" and bs="bs" and b'="b'"]
  27.389 -  by (induct p) (auto simp add: nth_pos2)
  27.390 -
  27.391 -primrec numsubst0:: "num \<Rightarrow> num \<Rightarrow> num" (* substitute a num into a num for Bound 0 *) where
  27.392 -  "numsubst0 t (C c) = (C c)"
  27.393 -  | "numsubst0 t (Bound n) = (if n=0 then t else Bound n)"
  27.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))"
  27.395 -  | "numsubst0 t (CF i a b) = CF i (numsubst0 t a) (numsubst0 t b)"
  27.396 -  | "numsubst0 t (Neg a) = Neg (numsubst0 t a)"
  27.397 -  | "numsubst0 t (Add a b) = Add (numsubst0 t a) (numsubst0 t b)"
  27.398 -  | "numsubst0 t (Sub a b) = Sub (numsubst0 t a) (numsubst0 t b)" 
  27.399 -  | "numsubst0 t (Mul i a) = Mul i (numsubst0 t a)"
  27.400 -  | "numsubst0 t (Floor a) = Floor (numsubst0 t a)"
  27.401 -
  27.402 -lemma numsubst0_I:
  27.403 -  shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b#bs) a)#bs) t"
  27.404 -  by (induct t) (simp_all add: nth_pos2)
  27.405 -
  27.406 -lemma numsubst0_I':
  27.407 -  assumes nb: "numbound0 a"
  27.408 -  shows "Inum (b#bs) (numsubst0 a t) = Inum ((Inum (b'#bs) a)#bs) t"
  27.409 -  by (induct t) (simp_all add: nth_pos2 numbound0_I[OF nb, where b="b" and b'="b'"])
  27.410 -
  27.411 -primrec subst0:: "num \<Rightarrow> fm \<Rightarrow> fm" (* substitue a num into a formula for Bound 0 *) where
  27.412 -  "subst0 t T = T"
  27.413 -  | "subst0 t F = F"
  27.414 -  | "subst0 t (Lt a) = Lt (numsubst0 t a)"
  27.415 -  | "subst0 t (Le a) = Le (numsubst0 t a)"
  27.416 -  | "subst0 t (Gt a) = Gt (numsubst0 t a)"
  27.417 -  | "subst0 t (Ge a) = Ge (numsubst0 t a)"
  27.418 -  | "subst0 t (Eq a) = Eq (numsubst0 t a)"
  27.419 -  | "subst0 t (NEq a) = NEq (numsubst0 t a)"
  27.420 -  | "subst0 t (Dvd i a) = Dvd i (numsubst0 t a)"
  27.421 -  | "subst0 t (NDvd i a) = NDvd i (numsubst0 t a)"
  27.422 -  | "subst0 t (NOT p) = NOT (subst0 t p)"
  27.423 -  | "subst0 t (And p q) = And (subst0 t p) (subst0 t q)"
  27.424 -  | "subst0 t (Or p q) = Or (subst0 t p) (subst0 t q)"
  27.425 -  | "subst0 t (Imp p q) = Imp (subst0 t p) (subst0 t q)"
  27.426 -  | "subst0 t (Iff p q) = Iff (subst0 t p) (subst0 t q)"
  27.427 -
  27.428 -lemma subst0_I: assumes qfp: "qfree p"
  27.429 -  shows "Ifm (b#bs) (subst0 a p) = Ifm ((Inum (b#bs) a)#bs) p"
  27.430 -  using qfp numsubst0_I[where b="b" and bs="bs" and a="a"]
  27.431 -  by (induct p) (simp_all add: nth_pos2 )
  27.432 -
  27.433 -consts
  27.434 -  decrnum:: "num \<Rightarrow> num" 
  27.435 -  decr :: "fm \<Rightarrow> fm"
  27.436 -
  27.437 -recdef decrnum "measure size"
  27.438 -  "decrnum (Bound n) = Bound (n - 1)"
  27.439 -  "decrnum (Neg a) = Neg (decrnum a)"
  27.440 -  "decrnum (Add a b) = Add (decrnum a) (decrnum b)"
  27.441 -  "decrnum (Sub a b) = Sub (decrnum a) (decrnum b)"
  27.442 -  "decrnum (Mul c a) = Mul c (decrnum a)"
  27.443 -  "decrnum (Floor a) = Floor (decrnum a)"
  27.444 -  "decrnum (CN n c a) = CN (n - 1) c (decrnum a)"
  27.445 -  "decrnum (CF c a b) = CF c (decrnum a) (decrnum b)"
  27.446 -  "decrnum a = a"
  27.447 -
  27.448 -recdef decr "measure size"
  27.449 -  "decr (Lt a) = Lt (decrnum a)"
  27.450 -  "decr (Le a) = Le (decrnum a)"
  27.451 -  "decr (Gt a) = Gt (decrnum a)"
  27.452 -  "decr (Ge a) = Ge (decrnum a)"
  27.453 -  "decr (Eq a) = Eq (decrnum a)"
  27.454 -  "decr (NEq a) = NEq (decrnum a)"
  27.455 -  "decr (Dvd i a) = Dvd i (decrnum a)"
  27.456 -  "decr (NDvd i a) = NDvd i (decrnum a)"
  27.457 -  "decr (NOT p) = NOT (decr p)" 
  27.458 -  "decr (And p q) = And (decr p) (decr q)"
  27.459 -  "decr (Or p q) = Or (decr p) (decr q)"
  27.460 -  "decr (Imp p q) = Imp (decr p) (decr q)"
  27.461 -  "decr (Iff p q) = Iff (decr p) (decr q)"
  27.462 -  "decr p = p"
  27.463 -
  27.464 -lemma decrnum: assumes nb: "numbound0 t"
  27.465 -  shows "Inum (x#bs) t = Inum bs (decrnum t)"
  27.466 -  using nb by (induct t rule: decrnum.induct, simp_all add: nth_pos2)
  27.467 -
  27.468 -lemma decr: assumes nb: "bound0 p"
  27.469 -  shows "Ifm (x#bs) p = Ifm bs (decr p)"
  27.470 -  using nb 
  27.471 -  by (induct p rule: decr.induct, simp_all add: nth_pos2 decrnum)
  27.472 -
  27.473 -lemma decr_qf: "bound0 p \<Longrightarrow> qfree (decr p)"
  27.474 -by (induct p, simp_all)
  27.475 -
  27.476 -consts 
  27.477 -  isatom :: "fm \<Rightarrow> bool" (* test for atomicity *)
  27.478 -recdef isatom "measure size"
  27.479 -  "isatom T = True"
  27.480 -  "isatom F = True"
  27.481 -  "isatom (Lt a) = True"
  27.482 -  "isatom (Le a) = True"
  27.483 -  "isatom (Gt a) = True"
  27.484 -  "isatom (Ge a) = True"
  27.485 -  "isatom (Eq a) = True"
  27.486 -  "isatom (NEq a) = True"
  27.487 -  "isatom (Dvd i b) = True"
  27.488 -  "isatom (NDvd i b) = True"
  27.489 -  "isatom p = False"
  27.490 -
  27.491 -lemma numsubst0_numbound0: assumes nb: "numbound0 t"
  27.492 -  shows "numbound0 (numsubst0 t a)"
  27.493 -using nb by (induct a, auto)
  27.494 -
  27.495 -lemma subst0_bound0: assumes qf: "qfree p" and nb: "numbound0 t"
  27.496 -  shows "bound0 (subst0 t p)"
  27.497 -using qf numsubst0_numbound0[OF nb] by (induct p, auto)
  27.498 -
  27.499 -lemma bound0_qf: "bound0 p \<Longrightarrow> qfree p"
  27.500 -by (induct p, simp_all)
  27.501 -
  27.502 -
  27.503 -definition djf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a \<Rightarrow> fm \<Rightarrow> fm" where
  27.504 -  "djf f p q = (if q=T then T else if q=F then f p else 
  27.505 -  (let fp = f p in case fp of T \<Rightarrow> T | F \<Rightarrow> q | _ \<Rightarrow> Or fp q))"
  27.506 -
  27.507 -definition evaldjf:: "('a \<Rightarrow> fm) \<Rightarrow> 'a list \<Rightarrow> fm" where
  27.508 -  "evaldjf f ps = foldr (djf f) ps F"
  27.509 -
  27.510 -lemma djf_Or: "Ifm bs (djf f p q) = Ifm bs (Or (f p) q)"
  27.511 -by (cases "q=T", simp add: djf_def,cases "q=F",simp add: djf_def) 
  27.512 -(cases "f p", simp_all add: Let_def djf_def) 
  27.513 -
  27.514 -lemma evaldjf_ex: "Ifm bs (evaldjf f ps) = (\<exists> p \<in> set ps. Ifm bs (f p))"
  27.515 -  by(induct ps, simp_all add: evaldjf_def djf_Or)
  27.516 -
  27.517 -lemma evaldjf_bound0: 
  27.518 -  assumes nb: "\<forall> x\<in> set xs. bound0 (f x)"
  27.519 -  shows "bound0 (evaldjf f xs)"
  27.520 -  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
  27.521 -
  27.522 -lemma evaldjf_qf: 
  27.523 -  assumes nb: "\<forall> x\<in> set xs. qfree (f x)"
  27.524 -  shows "qfree (evaldjf f xs)"
  27.525 -  using nb by (induct xs, auto simp add: evaldjf_def djf_def Let_def) (case_tac "f a", auto) 
  27.526 -
  27.527 -consts 
  27.528 -  disjuncts :: "fm \<Rightarrow> fm list" 
  27.529 -  conjuncts :: "fm \<Rightarrow> fm list"
  27.530 -recdef disjuncts "measure size"
  27.531 -  "disjuncts (Or p q) = (disjuncts p) @ (disjuncts q)"
  27.532 -  "disjuncts F = []"
  27.533 -  "disjuncts p = [p]"
  27.534 -
  27.535 -recdef conjuncts "measure size"
  27.536 -  "conjuncts (And p q) = (conjuncts p) @ (conjuncts q)"
  27.537 -  "conjuncts T = []"
  27.538 -  "conjuncts p = [p]"
  27.539 -lemma disjuncts: "(\<exists> q\<in> set (disjuncts p). Ifm bs q) = Ifm bs p"
  27.540 -by(induct p rule: disjuncts.induct, auto)
  27.541 -lemma conjuncts: "(\<forall> q\<in> set (conjuncts p). Ifm bs q) = Ifm bs p"
  27.542 -by(induct p rule: conjuncts.induct, auto)
  27.543 -
  27.544 -lemma disjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). bound0 q"
  27.545 -proof-
  27.546 -  assume nb: "bound0 p"
  27.547 -  hence "list_all bound0 (disjuncts p)" by (induct p rule:disjuncts.induct,auto)
  27.548 -  thus ?thesis by (simp only: list_all_iff)
  27.549 -qed
  27.550 -lemma conjuncts_nb: "bound0 p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). bound0 q"
  27.551 -proof-
  27.552 -  assume nb: "bound0 p"
  27.553 -  hence "list_all bound0 (conjuncts p)" by (induct p rule:conjuncts.induct,auto)
  27.554 -  thus ?thesis by (simp only: list_all_iff)
  27.555 -qed
  27.556 -
  27.557 -lemma disjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (disjuncts p). qfree q"
  27.558 -proof-
  27.559 -  assume qf: "qfree p"
  27.560 -  hence "list_all qfree (disjuncts p)"
  27.561 -    by (induct p rule: disjuncts.induct, auto)
  27.562 -  thus ?thesis by (simp only: list_all_iff)
  27.563 -qed
  27.564 -lemma conjuncts_qf: "qfree p \<Longrightarrow> \<forall> q\<in> set (conjuncts p). qfree q"
  27.565 -proof-
  27.566 -  assume qf: "qfree p"
  27.567 -  hence "list_all qfree (conjuncts p)"
  27.568 -    by (induct p rule: conjuncts.induct, auto)
  27.569 -  thus ?thesis by (simp only: list_all_iff)
  27.570 -qed
  27.571 -
  27.572 -constdefs DJ :: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
  27.573 -  "DJ f p \<equiv> evaldjf f (disjuncts p)"
  27.574 -
  27.575 -lemma DJ: assumes fdj: "\<forall> p q. f (Or p q) = Or (f p) (f q)"
  27.576 -  and fF: "f F = F"
  27.577 -  shows "Ifm bs (DJ f p) = Ifm bs (f p)"
  27.578 -proof-
  27.579 -  have "Ifm bs (DJ f p) = (\<exists> q \<in> set (disjuncts p). Ifm bs (f q))"
  27.580 -    by (simp add: DJ_def evaldjf_ex) 
  27.581 -  also have "\<dots> = Ifm bs (f p)" using fdj fF by (induct p rule: disjuncts.induct, auto)
  27.582 -  finally show ?thesis .
  27.583 -qed
  27.584 -
  27.585 -lemma DJ_qf: assumes 
  27.586 -  fqf: "\<forall> p. qfree p \<longrightarrow> qfree (f p)"
  27.587 -  shows "\<forall>p. qfree p \<longrightarrow> qfree (DJ f p) "
  27.588 -proof(clarify)
  27.589 -  fix  p assume qf: "qfree p"
  27.590 -  have th: "DJ f p = evaldjf f (disjuncts p)" by (simp add: DJ_def)
  27.591 -  from disjuncts_qf[OF qf] have "\<forall> q\<in> set (disjuncts p). qfree q" .
  27.592 -  with fqf have th':"\<forall> q\<in> set (disjuncts p). qfree (f q)" by blast
  27.593 -  
  27.594 -  from evaldjf_qf[OF th'] th show "qfree (DJ f p)" by simp
  27.595 -qed
  27.596 -
  27.597 -lemma DJ_qe: assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
  27.598 -  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (DJ qe p) \<and> (Ifm bs ((DJ qe p)) = Ifm bs (E p))"
  27.599 -proof(clarify)
  27.600 -  fix p::fm and bs
  27.601 -  assume qf: "qfree p"
  27.602 -  from qe have qth: "\<forall> p. qfree p \<longrightarrow> qfree (qe p)" by blast
  27.603 -  from DJ_qf[OF qth] qf have qfth:"qfree (DJ qe p)" by auto
  27.604 -  have "Ifm bs (DJ qe p) = (\<exists> q\<in> set (disjuncts p). Ifm bs (qe q))"
  27.605 -    by (simp add: DJ_def evaldjf_ex)
  27.606 -  also have "\<dots> = (\<exists> q \<in> set(disjuncts p). Ifm bs (E q))" using qe disjuncts_qf[OF qf] by auto
  27.607 -  also have "\<dots> = Ifm bs (E p)" by (induct p rule: disjuncts.induct, auto)
  27.608 -  finally show "qfree (DJ qe p) \<and> Ifm bs (DJ qe p) = Ifm bs (E p)" using qfth by blast
  27.609 -qed
  27.610 -  (* Simplification *)
  27.611 -
  27.612 -  (* Algebraic simplifications for nums *)
  27.613 -consts bnds:: "num \<Rightarrow> nat list"
  27.614 -  lex_ns:: "nat list \<times> nat list \<Rightarrow> bool"
  27.615 -recdef bnds "measure size"
  27.616 -  "bnds (Bound n) = [n]"
  27.617 -  "bnds (CN n c a) = n#(bnds a)"
  27.618 -  "bnds (Neg a) = bnds a"
  27.619 -  "bnds (Add a b) = (bnds a)@(bnds b)"
  27.620 -  "bnds (Sub a b) = (bnds a)@(bnds b)"
  27.621 -  "bnds (Mul i a) = bnds a"
  27.622 -  "bnds (Floor a) = bnds a"
  27.623 -  "bnds (CF c a b) = (bnds a)@(bnds b)"
  27.624 -  "bnds a = []"
  27.625 -recdef lex_ns "measure (\<lambda> (xs,ys). length xs + length ys)"
  27.626 -  "lex_ns ([], ms) = True"
  27.627 -  "lex_ns (ns, []) = False"
  27.628 -  "lex_ns (n#ns, m#ms) = (n<m \<or> ((n = m) \<and> lex_ns (ns,ms))) "
  27.629 -constdefs lex_bnd :: "num \<Rightarrow> num \<Rightarrow> bool"
  27.630 -  "lex_bnd t s \<equiv> lex_ns (bnds t, bnds s)"
  27.631 -
  27.632 -consts 
  27.633 -  numgcdh:: "num \<Rightarrow> int \<Rightarrow> int"
  27.634 -  reducecoeffh:: "num \<Rightarrow> int \<Rightarrow> num"
  27.635 -  dvdnumcoeff:: "num \<Rightarrow> int \<Rightarrow> bool"
  27.636 -consts maxcoeff:: "num \<Rightarrow> int"
  27.637 -recdef maxcoeff "measure size"
  27.638 -  "maxcoeff (C i) = abs i"
  27.639 -  "maxcoeff (CN n c t) = max (abs c) (maxcoeff t)"
  27.640 -  "maxcoeff (CF c t s) = max (abs c) (maxcoeff s)"
  27.641 -  "maxcoeff t = 1"
  27.642 -
  27.643 -lemma maxcoeff_pos: "maxcoeff t \<ge> 0"
  27.644 -  apply (induct t rule: maxcoeff.induct, auto) 
  27.645 -  done
  27.646 -
  27.647 -recdef numgcdh "measure size"
  27.648 -  "numgcdh (C i) = (\<lambda>g. zgcd i g)"
  27.649 -  "numgcdh (CN n c t) = (\<lambda>g. zgcd c (numgcdh t g))"
  27.650 -  "numgcdh (CF c s t) = (\<lambda>g. zgcd c (numgcdh t g))"
  27.651 -  "numgcdh t = (\<lambda>g. 1)"
  27.652 -
  27.653 -definition
  27.654 -  numgcd :: "num \<Rightarrow> int"
  27.655 -where
  27.656 -  numgcd_def: "numgcd t = numgcdh t (maxcoeff t)"
  27.657 -
  27.658 -recdef reducecoeffh "measure size"
  27.659 -  "reducecoeffh (C i) = (\<lambda> g. C (i div g))"
  27.660 -  "reducecoeffh (CN n c t) = (\<lambda> g. CN n (c div g) (reducecoeffh t g))"
  27.661 -  "reducecoeffh (CF c s t) = (\<lambda> g. CF (c div g)  s (reducecoeffh t g))"
  27.662 -  "reducecoeffh t = (\<lambda>g. t)"
  27.663 -
  27.664 -definition
  27.665 -  reducecoeff :: "num \<Rightarrow> num"
  27.666 -where
  27.667 -  reducecoeff_def: "reducecoeff t =
  27.668 -  (let g = numgcd t in 
  27.669 -  if g = 0 then C 0 else if g=1 then t else reducecoeffh t g)"
  27.670 -
  27.671 -recdef dvdnumcoeff "measure size"
  27.672 -  "dvdnumcoeff (C i) = (\<lambda> g. g dvd i)"
  27.673 -  "dvdnumcoeff (CN n c t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
  27.674 -  "dvdnumcoeff (CF c s t) = (\<lambda> g. g dvd c \<and> (dvdnumcoeff t g))"
  27.675 -  "dvdnumcoeff t = (\<lambda>g. False)"
  27.676 -
  27.677 -lemma dvdnumcoeff_trans: 
  27.678 -  assumes gdg: "g dvd g'" and dgt':"dvdnumcoeff t g'"
  27.679 -  shows "dvdnumcoeff t g"
  27.680 -  using dgt' gdg 
  27.681 -  by (induct t rule: dvdnumcoeff.induct, simp_all add: gdg zdvd_trans[OF gdg])
  27.682 -
  27.683 -declare zdvd_trans [trans add]
  27.684 -
  27.685 -lemma natabs0: "(nat (abs x) = 0) = (x = 0)"
  27.686 -by arith
  27.687 -
  27.688 -lemma numgcd0:
  27.689 -  assumes g0: "numgcd t = 0"
  27.690 -  shows "Inum bs t = 0"
  27.691 -proof-
  27.692 -  have "\<And>x. numgcdh t x= 0 \<Longrightarrow> Inum bs t = 0"
  27.693 -    by (induct t rule: numgcdh.induct, auto simp add: zgcd_def gcd_zero natabs0 max_def maxcoeff_pos)
  27.694 -  thus ?thesis using g0[simplified numgcd_def] by blast
  27.695 -qed
  27.696 -
  27.697 -lemma numgcdh_pos: assumes gp: "g \<ge> 0" shows "numgcdh t g \<ge> 0"
  27.698 -  using gp
  27.699 -  by (induct t rule: numgcdh.induct, auto simp add: zgcd_def)
  27.700 -
  27.701 -lemma numgcd_pos: "numgcd t \<ge>0"
  27.702 -  by (simp add: numgcd_def numgcdh_pos maxcoeff_pos)
  27.703 -
  27.704 -lemma reducecoeffh:
  27.705 -  assumes gt: "dvdnumcoeff t g" and gp: "g > 0" 
  27.706 -  shows "real g *(Inum bs (reducecoeffh t g)) = Inum bs t"
  27.707 -  using gt
  27.708 -proof(induct t rule: reducecoeffh.induct) 
  27.709 -  case (1 i) hence gd: "g dvd i" by simp
  27.710 -  from gp have gnz: "g \<noteq> 0" by simp
  27.711 -  from prems show ?case by (simp add: real_of_int_div[OF gnz gd])
  27.712 -next
  27.713 -  case (2 n c t)  hence gd: "g dvd c" by simp
  27.714 -  from gp have gnz: "g \<noteq> 0" by simp
  27.715 -  from prems show ?case by (simp add: real_of_int_div[OF gnz gd] ring_simps)
  27.716 -next
  27.717 -  case (3 c s t)  hence gd: "g dvd c" by simp
  27.718 -  from gp have gnz: "g \<noteq> 0" by simp
  27.719 -  from prems show ?case by (simp add: real_of_int_div[OF gnz gd] ring_simps) 
  27.720 -qed (auto simp add: numgcd_def gp)
  27.721 -consts ismaxcoeff:: "num \<Rightarrow> int \<Rightarrow> bool"
  27.722 -recdef ismaxcoeff "measure size"
  27.723 -  "ismaxcoeff (C i) = (\<lambda> x. abs i \<le> x)"
  27.724 -  "ismaxcoeff (CN n c t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
  27.725 -  "ismaxcoeff (CF c s t) = (\<lambda>x. abs c \<le> x \<and> (ismaxcoeff t x))"
  27.726 -  "ismaxcoeff t = (\<lambda>x. True)"
  27.727 -
  27.728 -lemma ismaxcoeff_mono: "ismaxcoeff t c \<Longrightarrow> c \<le> c' \<Longrightarrow> ismaxcoeff t c'"
  27.729 -by (induct t rule: ismaxcoeff.induct, auto)
  27.730 -
  27.731 -lemma maxcoeff_ismaxcoeff: "ismaxcoeff t (maxcoeff t)"
  27.732 -proof (induct t rule: maxcoeff.induct)
  27.733 -  case (2 n c t)
  27.734 -  hence H:"ismaxcoeff t (maxcoeff t)" .
  27.735 -  have thh: "maxcoeff t \<le> max (abs c) (maxcoeff t)" by (simp add: le_maxI2)
  27.736 -  from ismaxcoeff_mono[OF H thh] show ?case by (simp add: le_maxI1)
  27.737 -next
  27.738 -  case (3 c t s) 
  27.739 -  hence H1:"ismaxcoeff s (maxcoeff s)" by auto
  27.740 -  have thh1: "maxcoeff s \<le> max \<bar>c\<bar> (maxcoeff s)" by (simp add: max_def)
  27.741 -  from ismaxcoeff_mono[OF H1 thh1] show ?case by (simp add: le_maxI1)
  27.742 -qed simp_all
  27.743 -
  27.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))"
  27.745 -  apply (unfold zgcd_def)
  27.746 -  apply (cases "i = 0", simp_all)
  27.747 -  apply (cases "j = 0", simp_all)
  27.748 -  apply (cases "abs i = 1", simp_all)
  27.749 -  apply (cases "abs j = 1", simp_all)
  27.750 -  apply auto
  27.751 -  done
  27.752 -lemma numgcdh0:"numgcdh t m = 0 \<Longrightarrow>  m =0"
  27.753 -  by (induct t rule: numgcdh.induct, auto simp add:zgcd0)
  27.754 -
  27.755 -lemma dvdnumcoeff_aux:
  27.756 -  assumes "ismaxcoeff t m" and mp:"m \<ge> 0" and "numgcdh t m > 1"
  27.757 -  shows "dvdnumcoeff t (numgcdh t m)"
  27.758 -using prems
  27.759 -proof(induct t rule: numgcdh.induct)
  27.760 -  case (2 n c t) 
  27.761 -  let ?g = "numgcdh t m"
  27.762 -  from prems have th:"zgcd c ?g > 1" by simp
  27.763 -  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
  27.764 -  have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
  27.765 -  moreover {assume "abs c > 1" and gp: "?g > 1" with prems
  27.766 -    have th: "dvdnumcoeff t ?g" by simp
  27.767 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  27.768 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)}
  27.769 -  moreover {assume "abs c = 0 \<and> ?g > 1"
  27.770 -    with prems have th: "dvdnumcoeff t ?g" by simp
  27.771 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  27.772 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)
  27.773 -    hence ?case by simp }
  27.774 -  moreover {assume "abs c > 1" and g0:"?g = 0" 
  27.775 -    from numgcdh0[OF g0] have "m=0". with prems   have ?case by simp }
  27.776 -  ultimately show ?case by blast
  27.777 -next
  27.778 -  case (3 c s t) 
  27.779 -  let ?g = "numgcdh t m"
  27.780 -  from prems have th:"zgcd c ?g > 1" by simp
  27.781 -  from zgcd_gt1[OF th] numgcdh_pos[OF mp, where t="t"]
  27.782 -  have "(abs c > 1 \<and> ?g > 1) \<or> (abs c = 0 \<and> ?g > 1) \<or> (abs c > 1 \<and> ?g = 0)" by simp
  27.783 -  moreover {assume "abs c > 1" and gp: "?g > 1" with prems
  27.784 -    have th: "dvdnumcoeff t ?g" by simp
  27.785 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  27.786 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)}
  27.787 -  moreover {assume "abs c = 0 \<and> ?g > 1"
  27.788 -    with prems have th: "dvdnumcoeff t ?g" by simp
  27.789 -    have th': "zgcd c ?g dvd ?g" by (simp add:zgcd_zdvd2)
  27.790 -    from dvdnumcoeff_trans[OF th' th] have ?case by (simp add: zgcd_zdvd1)
  27.791 -    hence ?case by simp }
  27.792 -  moreover {assume "abs c > 1" and g0:"?g = 0" 
  27.793 -    from numgcdh0[OF g0] have "m=0". with prems   have ?case by simp }
  27.794 -  ultimately show ?case by blast
  27.795 -qed(auto simp add: zgcd_zdvd1)
  27.796 -
  27.797 -lemma dvdnumcoeff_aux2:
  27.798 -  assumes "numgcd t > 1" shows "dvdnumcoeff t (numgcd t) \<and> numgcd t > 0"
  27.799 -  using prems 
  27.800 -proof (simp add: numgcd_def)
  27.801 -  let ?mc = "maxcoeff t"
  27.802 -  let ?g = "numgcdh t ?mc"
  27.803 -  have th1: "ismaxcoeff t ?mc" by (rule maxcoeff_ismaxcoeff)
  27.804 -  have th2: "?mc \<ge> 0" by (rule maxcoeff_pos)
  27.805 -  assume H: "numgcdh t ?mc > 1"
  27.806 -  from dvdnumcoeff_aux[OF th1 th2 H]  show "dvdnumcoeff t ?g" .
  27.807 -qed
  27.808 -
  27.809 -lemma reducecoeff: "real (numgcd t) * (Inum bs (reducecoeff t)) = Inum bs t"
  27.810 -proof-
  27.811 -  let ?g = "numgcd t"
  27.812 -  have "?g \<ge> 0"  by (simp add: numgcd_pos)
  27.813 -  hence	"?g = 0 \<or> ?g = 1 \<or> ?g > 1" by auto
  27.814 -  moreover {assume "?g = 0" hence ?thesis by (simp add: numgcd0)} 
  27.815 -  moreover {assume "?g = 1" hence ?thesis by (simp add: reducecoeff_def)} 
  27.816 -  moreover { assume g1:"?g > 1"
  27.817 -    from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" and g0: "?g > 0" by blast+
  27.818 -    from reducecoeffh[OF th1 g0, where bs="bs"] g1 have ?thesis 
  27.819 -      by (simp add: reducecoeff_def Let_def)} 
  27.820 -  ultimately show ?thesis by blast
  27.821 -qed
  27.822 -
  27.823 -lemma reducecoeffh_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeffh t g)"
  27.824 -by (induct t rule: reducecoeffh.induct, auto)
  27.825 -
  27.826 -lemma reducecoeff_numbound0: "numbound0 t \<Longrightarrow> numbound0 (reducecoeff t)"
  27.827 -using reducecoeffh_numbound0 by (simp add: reducecoeff_def Let_def)
  27.828 -
  27.829 -consts
  27.830 -  simpnum:: "num \<Rightarrow> num"
  27.831 -  numadd:: "num \<times> num \<Rightarrow> num"
  27.832 -  nummul:: "num \<Rightarrow> int \<Rightarrow> num"
  27.833 -
  27.834 -recdef numadd "measure (\<lambda> (t,s). size t + size s)"
  27.835 -  "numadd (CN n1 c1 r1,CN n2 c2 r2) =
  27.836 -  (if n1=n2 then 
  27.837 -  (let c = c1 + c2
  27.838 -  in (if c=0 then numadd(r1,r2) else CN n1 c (numadd (r1,r2))))
  27.839 -  else if n1 \<le> n2 then CN n1 c1 (numadd (r1,CN n2 c2 r2))
  27.840 -  else (CN n2 c2 (numadd (CN n1 c1 r1,r2))))"
  27.841 -  "numadd (CN n1 c1 r1,t) = CN n1 c1 (numadd (r1, t))"  
  27.842 -  "numadd (t,CN n2 c2 r2) = CN n2 c2 (numadd (t,r2))" 
  27.843 -  "numadd (CF c1 t1 r1,CF c2 t2 r2) = 
  27.844 -   (if t1 = t2 then 
  27.845 -    (let c=c1+c2; s= numadd(r1,r2) in (if c=0 then s else CF c t1 s))
  27.846 -   else if lex_bnd t1 t2 then CF c1 t1 (numadd(r1,CF c2 t2 r2))
  27.847 -   else CF c2 t2 (numadd(CF c1 t1 r1,r2)))"
  27.848 -  "numadd (CF c1 t1 r1,C c) = CF c1 t1 (numadd (r1, C c))"
  27.849 -  "numadd (C c,CF c1 t1 r1) = CF c1 t1 (numadd (r1, C c))"
  27.850 -  "numadd (C b1, C b2) = C (b1+b2)"
  27.851 -  "numadd (a,b) = Add a b"
  27.852 -
  27.853 -lemma numadd[simp]: "Inum bs (numadd (t,s)) = Inum bs (Add t s)"
  27.854 -apply (induct t s rule: numadd.induct, simp_all add: Let_def)
  27.855 - apply (case_tac "c1+c2 = 0",case_tac "n1 \<le> n2", simp_all)
  27.856 -  apply (case_tac "n1 = n2", simp_all add: ring_simps)
  27.857 -  apply (simp only: left_distrib[symmetric])
  27.858 - apply simp
  27.859 -apply (case_tac "lex_bnd t1 t2", simp_all)
  27.860 - apply (case_tac "c1+c2 = 0")
  27.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)
  27.862 -
  27.863 -lemma numadd_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numadd (t,s))"
  27.864 -by (induct t s rule: numadd.induct, auto simp add: Let_def)
  27.865 -
  27.866 -recdef nummul "measure size"
  27.867 -  "nummul (C j) = (\<lambda> i. C (i*j))"
  27.868 -  "nummul (CN n c t) = (\<lambda> i. CN n (c*i) (nummul t i))"
  27.869 -  "nummul (CF c t s) = (\<lambda> i. CF (c*i) t (nummul s i))"
  27.870 -  "nummul (Mul c t) = (\<lambda> i. nummul t (i*c))"
  27.871 -  "nummul t = (\<lambda> i. Mul i t)"
  27.872 -
  27.873 -lemma nummul[simp]: "\<And> i. Inum bs (nummul t i) = Inum bs (Mul i t)"
  27.874 -by (induct t rule: nummul.induct, auto simp add: ring_simps)
  27.875 -
  27.876 -lemma nummul_nb[simp]: "\<And> i. numbound0 t \<Longrightarrow> numbound0 (nummul t i)"
  27.877 -by (induct t rule: nummul.induct, auto)
  27.878 -
  27.879 -constdefs numneg :: "num \<Rightarrow> num"
  27.880 -  "numneg t \<equiv> nummul t (- 1)"
  27.881 -
  27.882 -constdefs numsub :: "num \<Rightarrow> num \<Rightarrow> num"
  27.883 -  "numsub s t \<equiv> (if s = t then C 0 else numadd (s,numneg t))"
  27.884 -
  27.885 -lemma numneg[simp]: "Inum bs (numneg t) = Inum bs (Neg t)"
  27.886 -using numneg_def nummul by simp
  27.887 -
  27.888 -lemma numneg_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numneg t)"
  27.889 -using numneg_def by simp
  27.890 -
  27.891 -lemma numsub[simp]: "Inum bs (numsub a b) = Inum bs (Sub a b)"
  27.892 -using numsub_def by simp
  27.893 -
  27.894 -lemma numsub_nb[simp]: "\<lbrakk> numbound0 t ; numbound0 s\<rbrakk> \<Longrightarrow> numbound0 (numsub t s)"
  27.895 -using numsub_def by simp
  27.896 -
  27.897 -lemma isint_CF: assumes si: "isint s bs" shows "isint (CF c t s) bs"
  27.898 -proof-
  27.899 -  have cti: "isint (Mul c (Floor t)) bs" by (simp add: isint_Mul isint_Floor)
  27.900 -  
  27.901 -  have "?thesis = isint (Add (Mul c (Floor t)) s) bs" by (simp add: isint_def)
  27.902 -  also have "\<dots>" by (simp add: isint_add cti si)
  27.903 -  finally show ?thesis .
  27.904 -qed
  27.905 -
  27.906 -consts split_int:: "num \<Rightarrow> num\<times>num"
  27.907 -recdef split_int "measure num_size"
  27.908 -  "split_int (C c) = (C 0, C c)"
  27.909 -  "split_int (CN n c b) = 
  27.910 -     (let (bv,bi) = split_int b 
  27.911 -       in (CN n c bv, bi))"
  27.912 -  "split_int (CF c a b) = 
  27.913 -     (let (bv,bi) = split_int b 
  27.914 -       in (bv, CF c a bi))"
  27.915 -  "split_int a = (a,C 0)"
  27.916 -
  27.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"
  27.918 -proof (induct t rule: split_int.induct)
  27.919 -  case (2 c n b tv ti)
  27.920 -  let ?bv = "fst (split_int b)"
  27.921 -  let ?bi = "snd (split_int b)"
  27.922 -  have "split_int b = (?bv,?bi)" by simp
  27.923 -  with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
  27.924 -  from prems(2) have tibi: "ti = ?bi" by (simp add: Let_def split_def)
  27.925 -  from prems(2) b[symmetric] bii show ?case by (auto simp add: Let_def split_def)
  27.926 -next
  27.927 -  case (3 c a b tv ti) 
  27.928 -  let ?bv = "fst (split_int b)"
  27.929 -  let ?bi = "snd (split_int b)"
  27.930 -  have "split_int b = (?bv,?bi)" by simp
  27.931 -  with prems(1) have b:"Inum bs (Add ?bv ?bi) = Inum bs b" and bii: "isint ?bi bs" by blast+
  27.932 -  from prems(2) have tibi: "ti = CF c a ?bi" by (simp add: Let_def split_def)
  27.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)
  27.934 -qed (auto simp add: Let_def isint_iff isint_Floor isint_add isint_Mul split_def ring_simps)
  27.935 -
  27.936 -lemma split_int_nb: "numbound0 t \<Longrightarrow> numbound0 (fst (split_int t)) \<and> numbound0 (snd (split_int t)) "
  27.937 -by (induct t rule: split_int.induct, auto simp add: Let_def split_def)
  27.938 -
  27.939 -definition
  27.940 -  numfloor:: "num \<Rightarrow> num"
  27.941 -where
  27.942 -  numfloor_def: "numfloor t = (let (tv,ti) = split_int t in 
  27.943 -  (case tv of C i \<Rightarrow> numadd (tv,ti) 
  27.944 -  | _ \<Rightarrow> numadd(CF 1 tv (C 0),ti)))"
  27.945 -
  27.946 -lemma numfloor[simp]: "Inum bs (numfloor t) = Inum bs (Floor t)" (is "?n t = ?N (Floor t)")
  27.947 -proof-
  27.948 -  let ?tv = "fst (split_int t)"
  27.949 -  let ?ti = "snd (split_int t)"
  27.950 -  have tvti:"split_int t = (?tv,?ti)" by simp
  27.951 -  {assume H: "\<forall> v. ?tv \<noteq> C v"
  27.952 -    hence th1: "?n t = ?N (Add (Floor ?tv) ?ti)" 
  27.953 -      by (cases ?tv, auto simp add: numfloor_def Let_def split_def numadd)
  27.954 -    from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+
  27.955 -    hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp 
  27.956 -    also have "\<dots> = real (floor (?N ?tv) + (floor (?N ?ti)))"
  27.957 -      by (simp,subst tii[simplified isint_iff, symmetric]) simp
  27.958 -    also have "\<dots> = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff])
  27.959 -    finally have ?thesis using th1 by simp}
  27.960 -  moreover {fix v assume H:"?tv = C v" 
  27.961 -    from split_int[OF tvti] have "?N (Floor t) = ?N (Floor(Add ?tv ?ti))" and tii:"isint ?ti bs" by simp+
  27.962 -    hence "?N (Floor t) = real (floor (?N (Add ?tv ?ti)))" by simp 
  27.963 -    also have "\<dots> = real (floor (?N ?tv) + (floor (?N ?ti)))"
  27.964 -      by (simp,subst tii[simplified isint_iff, symmetric]) simp
  27.965 -    also have "\<dots> = ?N (Add (Floor ?tv) ?ti)" by (simp add: tii[simplified isint_iff])
  27.966 -    finally have ?thesis by (simp add: H numfloor_def Let_def split_def numadd) }
  27.967 -  ultimately show ?thesis by auto
  27.968 -qed
  27.969 -
  27.970 -lemma numfloor_nb[simp]: "numbound0 t \<Longrightarrow> numbound0 (numfloor t)"
  27.971 -  using split_int_nb[where t="t"]
  27.972 -  by (cases "fst(split_int t)" , auto simp add: numfloor_def Let_def split_def  numadd_nb)
  27.973 -
  27.974 -recdef simpnum "measure num_size"
  27.975 -  "simpnum (C j) = C j"
  27.976 -  "simpnum (Bound n) = CN n 1 (C 0)"
  27.977 -  "simpnum (Neg t) = numneg (simpnum t)"
  27.978 -  "simpnum (Add t s) = numadd (simpnum t,simpnum s)"
  27.979 -  "simpnum (Sub t s) = numsub (simpnum t) (simpnum s)"
  27.980 -  "simpnum (Mul i t) = (if i = 0 then (C 0) else nummul (simpnum t) i)"
  27.981 -  "simpnum (Floor t) = numfloor (simpnum t)"
  27.982 -  "simpnum (CN n c t) = (if c=0 then simpnum t else CN n c (simpnum t))"
  27.983 -  "simpnum (CF c t s) = simpnum(Add (Mul c (Floor t)) s)"
  27.984 -
  27.985 -lemma simpnum_ci[simp]: "Inum bs (simpnum t) = Inum bs t"
  27.986 -by (induct t rule: simpnum.induct, auto)
  27.987 -
  27.988 -lemma simpnum_numbound0[simp]: 
  27.989 -  "numbound0 t \<Longrightarrow> numbound0 (simpnum t)"
  27.990 -by (induct t rule: simpnum.induct, auto)
  27.991 -
  27.992 -consts nozerocoeff:: "num \<Rightarrow> bool"
  27.993 -recdef nozerocoeff "measure size"
  27.994 -  "nozerocoeff (C c) = True"
  27.995 -  "nozerocoeff (CN n c t) = (c\<noteq>0 \<and> nozerocoeff t)"
  27.996 -  "nozerocoeff (CF c s t) = (c \<noteq> 0 \<and> nozerocoeff t)"
  27.997 -  "nozerocoeff (Mul c t) = (c\<noteq>0 \<and> nozerocoeff t)"
  27.998 -  "nozerocoeff t = True"
  27.999 -
 27.1000 -lemma numadd_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numadd (a,b))"
 27.1001 -by (induct a b rule: numadd.induct,auto simp add: Let_def)
 27.1002 -
 27.1003 -lemma nummul_nz : "\<And> i. i\<noteq>0 \<Longrightarrow> nozerocoeff a \<Longrightarrow> nozerocoeff (nummul a i)"
 27.1004 -  by (induct a rule: nummul.induct,auto simp add: Let_def numadd_nz)
 27.1005 -
 27.1006 -lemma numneg_nz : "nozerocoeff a \<Longrightarrow> nozerocoeff (numneg a)"
 27.1007 -by (simp add: numneg_def nummul_nz)
 27.1008 -
 27.1009 -lemma numsub_nz: "nozerocoeff a \<Longrightarrow> nozerocoeff b \<Longrightarrow> nozerocoeff (numsub a b)"
 27.1010 -by (simp add: numsub_def numneg_nz numadd_nz)
 27.1011 -
 27.1012 -lemma split_int_nz: "nozerocoeff t \<Longrightarrow> nozerocoeff (fst (split_int t)) \<and> nozerocoeff (snd (split_int t))"
 27.1013 -by (induct t rule: split_int.induct,auto simp add: Let_def split_def)
 27.1014 -
 27.1015 -lemma numfloor_nz: "nozerocoeff t \<Longrightarrow> nozerocoeff (numfloor t)"
 27.1016 -by (simp add: numfloor_def Let_def split_def)
 27.1017 -(cases "fst (split_int t)", simp_all add: split_int_nz numadd_nz)
 27.1018 -
 27.1019 -lemma simpnum_nz: "nozerocoeff (simpnum t)"
 27.1020 -by(induct t rule: simpnum.induct, auto simp add: numadd_nz numneg_nz numsub_nz nummul_nz numfloor_nz)
 27.1021 -
 27.1022 -lemma maxcoeff_nz: "nozerocoeff t \<Longrightarrow> maxcoeff t = 0 \<Longrightarrow> t = C 0"
 27.1023 -proof (induct t rule: maxcoeff.induct)
 27.1024 -  case (2 n c t)
 27.1025 -  hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+
 27.1026 -  have "max (abs c) (maxcoeff t) \<ge> abs c" by (simp add: le_maxI1)
 27.1027 -  with cnz have "max (abs c) (maxcoeff t) > 0" by arith
 27.1028 -  with prems show ?case by simp
 27.1029 -next
 27.1030 -  case (3 c s t) 
 27.1031 -  hence cnz: "c \<noteq>0" and mx: "max (abs c) (maxcoeff t) = 0" by simp+
 27.1032 -  have "max (abs c) (maxcoeff t) \<ge> abs c" by (simp add: le_maxI1)
 27.1033 -  with cnz have "max (abs c) (maxcoeff t) > 0" by arith
 27.1034 -  with prems show ?case by simp
 27.1035 -qed auto
 27.1036 -
 27.1037 -lemma numgcd_nz: assumes nz: "nozerocoeff t" and g0: "numgcd t = 0" shows "t = C 0"
 27.1038 -proof-
 27.1039 -  from g0 have th:"numgcdh t (maxcoeff t) = 0" by (simp add: numgcd_def)
 27.1040 -  from numgcdh0[OF th]  have th:"maxcoeff t = 0" .
 27.1041 -  from maxcoeff_nz[OF nz th] show ?thesis .
 27.1042 -qed
 27.1043 -
 27.1044 -constdefs simp_num_pair:: "(num \<times> int) \<Rightarrow> num \<times> int"
 27.1045 -  "simp_num_pair \<equiv> (\<lambda> (t,n). (if n = 0 then (C 0, 0) else
 27.1046 -   (let t' = simpnum t ; g = numgcd t' in 
 27.1047 -      if g > 1 then (let g' = zgcd n g in 
 27.1048 -        if g' = 1 then (t',n) 
 27.1049 -        else (reducecoeffh t' g', n div g')) 
 27.1050 -      else (t',n))))"
 27.1051 -
 27.1052 -lemma simp_num_pair_ci:
 27.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))"
 27.1054 -  (is "?lhs = ?rhs")
 27.1055 -proof-
 27.1056 -  let ?t' = "simpnum t"
 27.1057 -  let ?g = "numgcd ?t'"
 27.1058 -  let ?g' = "zgcd n ?g"
 27.1059 -  {assume nz: "n = 0" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
 27.1060 -  moreover
 27.1061 -  { assume nnz: "n \<noteq> 0"
 27.1062 -    {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
 27.1063 -    moreover
 27.1064 -    {assume g1:"?g>1" hence g0: "?g > 0" by simp
 27.1065 -      from zgcd0 g1 nnz have gp0: "?g' \<noteq> 0" by simp
 27.1066 -      hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith
 27.1067 -      hence "?g'= 1 \<or> ?g' > 1" by arith
 27.1068 -      moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simp_num_pair_def)}
 27.1069 -      moreover {assume g'1:"?g'>1"
 27.1070 -	from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff ?t' ?g" ..
 27.1071 -	let ?tt = "reducecoeffh ?t' ?g'"
 27.1072 -	let ?t = "Inum bs ?tt"
 27.1073 -	have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
 27.1074 -	have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) 
 27.1075 -	have gpdgp: "?g' dvd ?g'" by simp
 27.1076 -	from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] 
 27.1077 -	have th2:"real ?g' * ?t = Inum bs ?t'" by simp
 27.1078 -	from prems have "?lhs = ?t / real (n div ?g')" by (simp add: simp_num_pair_def Let_def)
 27.1079 -	also have "\<dots> = (real ?g' * ?t) / (real ?g' * (real (n div ?g')))" by simp
 27.1080 -	also have "\<dots> = (Inum bs ?t' / real n)"
 27.1081 -	  using real_of_int_div[OF gp0 gpdd] th2 gp0 by simp
 27.1082 -	finally have "?lhs = Inum bs t / real n" by simp
 27.1083 -	then have ?thesis using prems by (simp add: simp_num_pair_def)}
 27.1084 -      ultimately have ?thesis by blast}
 27.1085 -    ultimately have ?thesis by blast} 
 27.1086 -  ultimately show ?thesis by blast
 27.1087 -qed
 27.1088 -
 27.1089 -lemma simp_num_pair_l: assumes tnb: "numbound0 t" and np: "n >0" and tn: "simp_num_pair (t,n) = (t',n')"
 27.1090 -  shows "numbound0 t' \<and> n' >0"
 27.1091 -proof-
 27.1092 -    let ?t' = "simpnum t"
 27.1093 -  let ?g = "numgcd ?t'"
 27.1094 -  let ?g' = "zgcd n ?g"
 27.1095 -  {assume nz: "n = 0" hence ?thesis using prems by (simp add: Let_def simp_num_pair_def)}
 27.1096 -  moreover
 27.1097 -  { assume nnz: "n \<noteq> 0"
 27.1098 -    {assume "\<not> ?g > 1" hence ?thesis  using prems by (auto simp add: Let_def simp_num_pair_def)}
 27.1099 -    moreover
 27.1100 -    {assume g1:"?g>1" hence g0: "?g > 0" by simp
 27.1101 -      from zgcd0 g1 nnz have gp0: "?g' \<noteq> 0" by simp
 27.1102 -      hence g'p: "?g' > 0" using zgcd_pos[where i="n" and j="numgcd ?t'"] by arith
 27.1103 -      hence "?g'= 1 \<or> ?g' > 1" by arith
 27.1104 -      moreover {assume "?g'=1" hence ?thesis using prems 
 27.1105 -	  by (auto simp add: Let_def simp_num_pair_def)}
 27.1106 -      moreover {assume g'1:"?g'>1"
 27.1107 -	have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
 27.1108 -	have gpdd: "?g' dvd n" by (simp add: zgcd_zdvd1) 
 27.1109 -	have gpdgp: "?g' dvd ?g'" by simp
 27.1110 -	from zdvd_imp_le[OF gpdd np] have g'n: "?g' \<le> n" .
 27.1111 -	from zdiv_mono1[OF g'n g'p, simplified zdiv_self[OF gp0]]
 27.1112 -	have "n div ?g' >0" by simp
 27.1113 -	hence ?thesis using prems 
 27.1114 -	  by(auto simp add: simp_num_pair_def Let_def reducecoeffh_numbound0)}
 27.1115 -      ultimately have ?thesis by blast}
 27.1116 -    ultimately have ?thesis by blast} 
 27.1117 -  ultimately show ?thesis by blast
 27.1118 -qed
 27.1119 -
 27.1120 -consts not:: "fm \<Rightarrow> fm"
 27.1121 -recdef not "measure size"
 27.1122 -  "not (NOT p) = p"
 27.1123 -  "not T = F"
 27.1124 -  "not F = T"
 27.1125 -  "not (Lt t) = Ge t"
 27.1126 -  "not (Le t) = Gt t"
 27.1127 -  "not (Gt t) = Le t"
 27.1128 -  "not (Ge t) = Lt t"
 27.1129 -  "not (Eq t) = NEq t"
 27.1130 -  "not (NEq t) = Eq t"
 27.1131 -  "not (Dvd i t) = NDvd i t"
 27.1132 -  "not (NDvd i t) = Dvd i t"
 27.1133 -  "not (And p q) = Or (not p) (not q)"
 27.1134 -  "not (Or p q) = And (not p) (not q)"
 27.1135 -  "not p = NOT p"
 27.1136 -lemma not[simp]: "Ifm bs (not p) = Ifm bs (NOT p)"
 27.1137 -by (induct p) auto
 27.1138 -lemma not_qf[simp]: "qfree p \<Longrightarrow> qfree (not p)"
 27.1139 -by (induct p, auto)
 27.1140 -lemma not_nb[simp]: "bound0 p \<Longrightarrow> bound0 (not p)"
 27.1141 -by (induct p, auto)
 27.1142 -
 27.1143 -constdefs conj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 27.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 
 27.1145 -   if p = q then p else And p q)"
 27.1146 -lemma conj[simp]: "Ifm bs (conj p q) = Ifm bs (And p q)"
 27.1147 -by (cases "p=F \<or> q=F",simp_all add: conj_def) (cases p,simp_all)
 27.1148 -
 27.1149 -lemma conj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (conj p q)"
 27.1150 -using conj_def by auto 
 27.1151 -lemma conj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (conj p q)"
 27.1152 -using conj_def by auto 
 27.1153 -
 27.1154 -constdefs disj :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 27.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 
 27.1156 -       else if p=q then p else Or p q)"
 27.1157 -
 27.1158 -lemma disj[simp]: "Ifm bs (disj p q) = Ifm bs (Or p q)"
 27.1159 -by (cases "p=T \<or> q=T",simp_all add: disj_def) (cases p,simp_all)
 27.1160 -lemma disj_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (disj p q)"
 27.1161 -using disj_def by auto 
 27.1162 -lemma disj_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (disj p q)"
 27.1163 -using disj_def by auto 
 27.1164 -
 27.1165 -constdefs   imp :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 27.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 
 27.1167 -    else Imp p q)"
 27.1168 -lemma imp[simp]: "Ifm bs (imp p q) = Ifm bs (Imp p q)"
 27.1169 -by (cases "p=F \<or> q=T",simp_all add: imp_def)
 27.1170 -lemma imp_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (imp p q)"
 27.1171 -using imp_def by (cases "p=F \<or> q=T",simp_all add: imp_def)
 27.1172 -lemma imp_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (imp p q)"
 27.1173 -using imp_def by (cases "p=F \<or> q=T \<or> p=q",simp_all add: imp_def) 
 27.1174 -
 27.1175 -constdefs   iff :: "fm \<Rightarrow> fm \<Rightarrow> fm"
 27.1176 -  "iff p q \<equiv> (if (p = q) then T else if (p = not q \<or> not p = q) then F else 
 27.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 
 27.1178 -  Iff p q)"
 27.1179 -lemma iff[simp]: "Ifm bs (iff p q) = Ifm bs (Iff p q)"
 27.1180 -  by (unfold iff_def,cases "p=q", simp,cases "p=not q", simp add:not) 
 27.1181 -(cases "not p= q", auto simp add:not)
 27.1182 -lemma iff_qf[simp]: "\<lbrakk>qfree p ; qfree q\<rbrakk> \<Longrightarrow> qfree (iff p q)"
 27.1183 -  by (unfold iff_def,cases "p=q", auto)
 27.1184 -lemma iff_nb[simp]: "\<lbrakk>bound0 p ; bound0 q\<rbrakk> \<Longrightarrow> bound0 (iff p q)"
 27.1185 -using iff_def by (unfold iff_def,cases "p=q", auto)
 27.1186 -
 27.1187 -consts check_int:: "num \<Rightarrow> bool"
 27.1188 -recdef check_int "measure size"
 27.1189 -  "check_int (C i) = True"
 27.1190 -  "check_int (Floor t) = True"
 27.1191 -  "check_int (Mul i t) = check_int t"
 27.1192 -  "check_int (Add t s) = (check_int t \<and> check_int s)"
 27.1193 -  "check_int (Neg t) = check_int t"
 27.1194 -  "check_int (CF c t s) = check_int s"
 27.1195 -  "check_int t = False"
 27.1196 -lemma check_int: "check_int t \<Longrightarrow> isint t bs"
 27.1197 -by (induct t, auto simp add: isint_add isint_Floor isint_Mul isint_neg isint_c isint_CF)
 27.1198 -
 27.1199 -lemma rdvd_left1_int: "real \<lfloor>t\<rfloor> = t \<Longrightarrow> 1 rdvd t"
 27.1200 -  by (simp add: rdvd_def,rule_tac x="\<lfloor>t\<rfloor>" in exI) simp
 27.1201 -
 27.1202 -lemma rdvd_reduce: 
 27.1203 -  assumes gd:"g dvd d" and gc:"g dvd c" and gp: "g > 0"
 27.1204 -  shows "real (d::int) rdvd real (c::int)*t = (real (d div g) rdvd real (c div g)*t)"
 27.1205 -proof
 27.1206 -  assume d: "real d rdvd real c * t"
 27.1207 -  from d rdvd_def obtain k where k_def: "real c * t = real d* real (k::int)" by auto
 27.1208 -  from gd dvd_def obtain kd where kd_def: "d = g * kd" by auto
 27.1209 -  from gc dvd_def obtain kc where kc_def: "c = g * kc" by auto
 27.1210 -  from k_def kd_def kc_def have "real g * real kc * t = real g * real kd * real k" by simp
 27.1211 -  hence "real kc * t = real kd * real k" using gp by simp
 27.1212 -  hence th:"real kd rdvd real kc * t" using rdvd_def by blast
 27.1213 -  from kd_def gp have th':"kd = d div g" by simp
 27.1214 -  from kc_def gp have "kc = c div g" by simp
 27.1215 -  with th th' show "real (d div g) rdvd real (c div g) * t" by simp
 27.1216 -next
 27.1217 -  assume d: "real (d div g) rdvd real (c div g) * t"
 27.1218 -  from gp have gnz: "g \<noteq> 0" by simp
 27.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
 27.1220 -qed
 27.1221 -
 27.1222 -constdefs simpdvd:: "int \<Rightarrow> num \<Rightarrow> (int \<times> num)"
 27.1223 -  "simpdvd d t \<equiv> 
 27.1224 -   (let g = numgcd t in 
 27.1225 -      if g > 1 then (let g' = zgcd d g in 
 27.1226 -        if g' = 1 then (d, t) 
 27.1227 -        else (d div g',reducecoeffh t g')) 
 27.1228 -      else (d, t))"
 27.1229 -lemma simpdvd: 
 27.1230 -  assumes tnz: "nozerocoeff t" and dnz: "d \<noteq> 0"
 27.1231 -  shows "Ifm bs (Dvd (fst (simpdvd d t)) (snd (simpdvd d t))) = Ifm bs (Dvd d t)"
 27.1232 -proof-
 27.1233 -  let ?g = "numgcd t"
 27.1234 -  let ?g' = "zgcd d ?g"
 27.1235 -  {assume "\<not> ?g > 1" hence ?thesis by (simp add: Let_def simpdvd_def)}
 27.1236 -  moreover
 27.1237 -  {assume g1:"?g>1" hence g0: "?g > 0" by simp
 27.1238 -    from zgcd0 g1 dnz have gp0: "?g' \<noteq> 0" by simp
 27.1239 -    hence g'p: "?g' > 0" using zgcd_pos[where i="d" and j="numgcd t"] by arith
 27.1240 -    hence "?g'= 1 \<or> ?g' > 1" by arith
 27.1241 -    moreover {assume "?g'=1" hence ?thesis by (simp add: Let_def simpdvd_def)}
 27.1242 -    moreover {assume g'1:"?g'>1"
 27.1243 -      from dvdnumcoeff_aux2[OF g1] have th1:"dvdnumcoeff t ?g" ..
 27.1244 -      let ?tt = "reducecoeffh t ?g'"
 27.1245 -      let ?t = "Inum bs ?tt"
 27.1246 -      have gpdg: "?g' dvd ?g" by (simp add: zgcd_zdvd2)
 27.1247 -      have gpdd: "?g' dvd d" by (simp add: zgcd_zdvd1) 
 27.1248 -      have gpdgp: "?g' dvd ?g'" by simp
 27.1249 -      from reducecoeffh[OF dvdnumcoeff_trans[OF gpdg th1] g'p] 
 27.1250 -      have th2:"real ?g' * ?t = Inum bs t" by simp
 27.1251 -      from prems have "Ifm bs (Dvd (fst (simpdvd d t)) (snd(simpdvd d t))) = Ifm bs (Dvd (d div ?g') ?tt)"
 27.1252 -	by (simp add: simpdvd_def Let_def)
 27.1253 -      also have "\<dots> = (real d rdvd (Inum bs t))"
 27.1254 -	using rdvd_reduce[OF gpdd gpdgp g'p, where t="?t", simplified zdiv_self[OF gp0]] 
 27.1255 -	  th2[symmetric] by simp
 27.1256 -      finally have ?thesis by simp  }
 27.1257 -    ultimately have ?thesis by blast
 27.1258 -  }
 27.1259 -  ultimately show ?thesis by blast
 27.1260 -qed
 27.1261 -
 27.1262 -consts simpfm :: "fm \<Rightarrow> fm"
 27.1263 -recdef simpfm "measure fmsize"
 27.1264 -  "simpfm (And p q) = conj (simpfm p) (simpfm q)"
 27.1265 -  "simpfm (Or p q) = disj (simpfm p) (simpfm q)"
 27.1266 -  "simpfm (Imp p q) = imp (simpfm p) (simpfm q)"
 27.1267 -  "simpfm (Iff p q) = iff (simpfm p) (simpfm q)"
 27.1268 -  "simpfm (NOT p) = not (simpfm p)"
 27.1269 -  "simpfm (Lt a) = (let a' = simpnum a in case a' of C v \<Rightarrow> if (v < 0) then T else F 
 27.1270 -  | _ \<Rightarrow> Lt (reducecoeff a'))"
 27.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'))"
 27.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'))"
 27.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'))"
 27.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'))"
 27.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'))"
 27.1276 -  "simpfm (Dvd i a) = (if i=0 then simpfm (Eq a)
 27.1277 -             else if (abs i = 1) \<and> check_int a then T
 27.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))"
 27.1279 -  "simpfm (NDvd i a) = (if i=0 then simpfm (NEq a) 
 27.1280 -             else if (abs i = 1) \<and> check_int a then F
 27.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))"
 27.1282 -  "simpfm p = p"
 27.1283 -
 27.1284 -lemma simpfm[simp]: "Ifm bs (simpfm p) = Ifm bs p"
 27.1285 -proof(induct p rule: simpfm.induct)
 27.1286 -  case (6 a) let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 27.1287 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 27.1288 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 27.1289 -    let ?g = "numgcd ?sa"
 27.1290 -    let ?rsa = "reducecoeff ?sa"
 27.1291 -    let ?r = "Inum bs ?rsa"
 27.1292 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 27.1293 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 27.1294 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 27.1295 -    hence gp: "real ?g > 0" by simp
 27.1296 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 27.1297 -    with sa have "Inum bs a < 0 = (real ?g * ?r < real ?g * 0)" by simp
 27.1298 -    also have "\<dots> = (?r < 0)" using gp
 27.1299 -      by (simp only: mult_less_cancel_left) simp
 27.1300 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 27.1301 -  ultimately show ?case by blast
 27.1302 -next
 27.1303 -  case (7 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 27.1304 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 27.1305 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 27.1306 -    let ?g = "numgcd ?sa"
 27.1307 -    let ?rsa = "reducecoeff ?sa"
 27.1308 -    let ?r = "Inum bs ?rsa"
 27.1309 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 27.1310 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 27.1311 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 27.1312 -    hence gp: "real ?g > 0" by simp
 27.1313 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 27.1314 -    with sa have "Inum bs a \<le> 0 = (real ?g * ?r \<le> real ?g * 0)" by simp
 27.1315 -    also have "\<dots> = (?r \<le> 0)" using gp
 27.1316 -      by (simp only: mult_le_cancel_left) simp
 27.1317 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 27.1318 -  ultimately show ?case by blast
 27.1319 -next
 27.1320 -  case (8 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 27.1321 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 27.1322 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 27.1323 -    let ?g = "numgcd ?sa"
 27.1324 -    let ?rsa = "reducecoeff ?sa"
 27.1325 -    let ?r = "Inum bs ?rsa"
 27.1326 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 27.1327 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 27.1328 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 27.1329 -    hence gp: "real ?g > 0" by simp
 27.1330 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 27.1331 -    with sa have "Inum bs a > 0 = (real ?g * ?r > real ?g * 0)" by simp
 27.1332 -    also have "\<dots> = (?r > 0)" using gp
 27.1333 -      by (simp only: mult_less_cancel_left) simp
 27.1334 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 27.1335 -  ultimately show ?case by blast
 27.1336 -next
 27.1337 -  case (9 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 27.1338 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 27.1339 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 27.1340 -    let ?g = "numgcd ?sa"
 27.1341 -    let ?rsa = "reducecoeff ?sa"
 27.1342 -    let ?r = "Inum bs ?rsa"
 27.1343 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 27.1344 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 27.1345 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 27.1346 -    hence gp: "real ?g > 0" by simp
 27.1347 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 27.1348 -    with sa have "Inum bs a \<ge> 0 = (real ?g * ?r \<ge> real ?g * 0)" by simp
 27.1349 -    also have "\<dots> = (?r \<ge> 0)" using gp
 27.1350 -      by (simp only: mult_le_cancel_left) simp
 27.1351 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 27.1352 -  ultimately show ?case by blast
 27.1353 -next
 27.1354 -  case (10 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 27.1355 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 27.1356 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 27.1357 -    let ?g = "numgcd ?sa"
 27.1358 -    let ?rsa = "reducecoeff ?sa"
 27.1359 -    let ?r = "Inum bs ?rsa"
 27.1360 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 27.1361 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 27.1362 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 27.1363 -    hence gp: "real ?g > 0" by simp
 27.1364 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 27.1365 -    with sa have "Inum bs a = 0 = (real ?g * ?r = 0)" by simp
 27.1366 -    also have "\<dots> = (?r = 0)" using gp
 27.1367 -      by (simp add: mult_eq_0_iff)
 27.1368 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 27.1369 -  ultimately show ?case by blast
 27.1370 -next
 27.1371 -  case (11 a)  let ?sa = "simpnum a" have sa: "Inum bs ?sa = Inum bs a" by simp
 27.1372 -  {fix v assume "?sa = C v" hence ?case using sa by simp }
 27.1373 -  moreover {assume H:"\<not> (\<exists> v. ?sa = C v)"
 27.1374 -    let ?g = "numgcd ?sa"
 27.1375 -    let ?rsa = "reducecoeff ?sa"
 27.1376 -    let ?r = "Inum bs ?rsa"
 27.1377 -    have sa_nz: "nozerocoeff ?sa" by (rule simpnum_nz)
 27.1378 -    {assume gz: "?g=0" from numgcd_nz[OF sa_nz gz] H have "False" by auto}
 27.1379 -    with numgcd_pos[where t="?sa"] have "?g > 0" by (cases "?g=0", auto)
 27.1380 -    hence gp: "real ?g > 0" by simp
 27.1381 -    have "Inum bs ?sa = real ?g* ?r" by (simp add: reducecoeff)
 27.1382 -    with sa have "Inum bs a \<noteq> 0 = (real ?g * ?r \<noteq> 0)" by simp
 27.1383 -    also have "\<dots> = (?r \<noteq> 0)" using gp
 27.1384 -      by (simp add: mult_eq_0_iff)
 27.1385 -    finally have ?case using H by (cases "?sa" , simp_all add: Let_def)}
 27.1386 -  ultimately show ?case by blast
 27.1387 -next
 27.1388 -  case (12 i a)  let ?sa = "simpnum a"   have sa: "Inum bs ?sa = Inum bs a" by simp
 27.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
 27.1390 -  {assume "i=0" hence ?case using "12.hyps" by (simp add: rdvd_left_0_eq Let_def)}
 27.1391 -  moreover 
 27.1392 -  {assume ai1: "abs i = 1" and ai: "check_int a" 
 27.1393 -    hence "i=1 \<or> i= - 1" by arith
 27.1394 -    moreover {assume i1: "i = 1" 
 27.1395 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 27.1396 -      have ?case using i1 ai by simp }
 27.1397 -    moreover {assume i1: "i = - 1" 
 27.1398 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 27.1399 -	rdvd_abs1[where d="- 1" and t="Inum bs a"]
 27.1400 -      have ?case using i1 ai by simp }
 27.1401 -    ultimately have ?case by blast}
 27.1402 -  moreover   
 27.1403 -  {assume inz: "i\<noteq>0" and cond: "(abs i \<noteq> 1) \<or> (\<not> check_int a)"
 27.1404 -    {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
 27.1405 -	by (cases "abs i = 1", auto simp add: int_rdvd_iff) }
 27.1406 -    moreover {assume H:"\<not> (\<exists> v. ?sa = C v)" 
 27.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)
 27.1408 -      from simpnum_nz have nz:"nozerocoeff ?sa" by simp
 27.1409 -      from simpdvd [OF nz inz] th have ?case using sa by simp}
 27.1410 -    ultimately have ?case by blast}
 27.1411 -  ultimately show ?case by blast
 27.1412 -next
 27.1413 -  case (13 i a)  let ?sa = "simpnum a"   have sa: "Inum bs ?sa = Inum bs a" by simp
 27.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
 27.1415 -  {assume "i=0" hence ?case using "13.hyps" by (simp add: rdvd_left_0_eq Let_def)}
 27.1416 -  moreover 
 27.1417 -  {assume ai1: "abs i = 1" and ai: "check_int a" 
 27.1418 -    hence "i=1 \<or> i= - 1" by arith
 27.1419 -    moreover {assume i1: "i = 1" 
 27.1420 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 27.1421 -      have ?case using i1 ai by simp }
 27.1422 -    moreover {assume i1: "i = - 1" 
 27.1423 -      from rdvd_left1_int[OF check_int[OF ai, simplified isint_iff]] 
 27.1424 -	rdvd_abs1[where d="- 1" and t="Inum bs a"]
 27.1425 -      have ?case using i1 ai by simp }
 27.1426 -    ultimately have ?case by blast}
 27.1427 -  moreover   
 27.1428 -  {assume inz: "i\<noteq>0" and cond: "(abs i \<noteq> 1) \<or> (\<not> check_int a)"
 27.1429 -    {fix v assume "?sa = C v" hence ?case using sa[symmetric] inz cond
 27.1430 -	by (cases "abs i = 1", auto simp add: int_rdvd_iff) }
 27.1431 -    moreover {assume H:"\<not> (\<exists> v. ?sa = C v)" 
 27.1432 -      hence th: "simpfm (NDvd i a) = NDvd (fst (simpdvd i ?sa)) (snd (simpdvd i ?sa))" using inz cond 
 27.1433 -	by (cases ?sa, auto simp add: Let_def split_def)
 27.1434 -      from simpnum_nz have nz:"nozerocoeff ?sa" by simp
 27.1435 -      from simpdvd [OF nz inz] th have ?case using sa by simp}
 27.1436 -    ultimately have ?case by blast}
 27.1437 -  ultimately show ?case by blast
 27.1438 -qed (induct p rule: simpfm.induct, simp_all)
 27.1439 -
 27.1440 -lemma simpdvd_numbound0: "numbound0 t \<Longrightarrow> numbound0 (snd (simpdvd d t))"
 27.1441 -  by (simp add: simpdvd_def Let_def split_def reducecoeffh_numbound0)
 27.1442 -
 27.1443 -lemma simpfm_bound0[simp]: "bound0 p \<Longrightarrow> bound0 (simpfm p)"
 27.1444 -proof(induct p rule: simpfm.induct)
 27.1445 -  case (6 a) hence nb: "numbound0 a" by simp
 27.1446 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1447 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 27.1448 -next
 27.1449 -  case (7 a) hence nb: "numbound0 a" by simp
 27.1450 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1451 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 27.1452 -next
 27.1453 -  case (8 a) hence nb: "numbound0 a" by simp
 27.1454 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1455 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 27.1456 -next
 27.1457 -  case (9 a) hence nb: "numbound0 a" by simp
 27.1458 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1459 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 27.1460 -next
 27.1461 -  case (10 a) hence nb: "numbound0 a" by simp
 27.1462 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1463 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 27.1464 -next
 27.1465 -  case (11 a) hence nb: "numbound0 a" by simp
 27.1466 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1467 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0)
 27.1468 -next
 27.1469 -  case (12 i a) hence nb: "numbound0 a" by simp
 27.1470 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1471 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def)
 27.1472 -next
 27.1473 -  case (13 i a) hence nb: "numbound0 a" by simp
 27.1474 -  hence "numbound0 (simpnum a)" by (simp only: simpnum_numbound0[OF nb])
 27.1475 -  thus ?case by (cases "simpnum a", auto simp add: Let_def reducecoeff_numbound0 simpdvd_numbound0 split_def)
 27.1476 -qed(auto simp add: disj_def imp_def iff_def conj_def)
 27.1477 -
 27.1478 -lemma simpfm_qf[simp]: "qfree p \<Longrightarrow> qfree (simpfm p)"
 27.1479 -by (induct p rule: simpfm.induct, auto simp add: Let_def)
 27.1480 -(case_tac "simpnum a",auto simp add: split_def Let_def)+
 27.1481 -
 27.1482 -
 27.1483 -  (* Generic quantifier elimination *)
 27.1484 -
 27.1485 -constdefs list_conj :: "fm list \<Rightarrow> fm"
 27.1486 -  "list_conj ps \<equiv> foldr conj ps T"
 27.1487 -lemma list_conj: "Ifm bs (list_conj ps) = (\<forall>p\<in> set ps. Ifm bs p)"
 27.1488 -  by (induct ps, auto simp add: list_conj_def)
 27.1489 -lemma list_conj_qf: " \<forall>p\<in> set ps. qfree p \<Longrightarrow> qfree (list_conj ps)"
 27.1490 -  by (induct ps, auto simp add: list_conj_def)
 27.1491 -lemma list_conj_nb: " \<forall>p\<in> set ps. bound0 p \<Longrightarrow> bound0 (list_conj ps)"
 27.1492 -  by (induct ps, auto simp add: list_conj_def)
 27.1493 -constdefs CJNB:: "(fm \<Rightarrow> fm) \<Rightarrow> fm \<Rightarrow> fm"
 27.1494 -  "CJNB f p \<equiv> (let cjs = conjuncts p ; (yes,no) = partition bound0 cjs
 27.1495 -                   in conj (decr (list_conj yes)) (f (list_conj no)))"
 27.1496 -
 27.1497 -lemma CJNB_qe: 
 27.1498 -  assumes qe: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
 27.1499 -  shows "\<forall> bs p. qfree p \<longrightarrow> qfree (CJNB qe p) \<and> (Ifm bs ((CJNB qe p)) = Ifm bs (E p))"
 27.1500 -proof(clarify)
 27.1501 -  fix bs p
 27.1502 -  assume qfp: "qfree p"
 27.1503 -  let ?cjs = "conjuncts p"
 27.1504 -  let ?yes = "fst (partition bound0 ?cjs)"
 27.1505 -  let ?no = "snd (partition bound0 ?cjs)"
 27.1506 -  let ?cno = "list_conj ?no"
 27.1507 -  let ?cyes = "list_conj ?yes"
 27.1508 -  have part: "partition bound0 ?cjs = (?yes,?no)" by simp
 27.1509 -  from partition_P[OF part] have "\<forall> q\<in> set ?yes. bound0 q" by blast 
 27.1510 -  hence yes_nb: "bound0 ?cyes" by (simp add: list_conj_nb) 
 27.1511 -  hence yes_qf: "qfree (decr ?cyes )" by (simp add: decr_qf)
 27.1512 -  from conjuncts_qf[OF qfp] partition_set[OF part] 
 27.1513 -  have " \<forall>q\<in> set ?no. qfree q" by auto
 27.1514 -  hence no_qf: "qfree ?cno"by (simp add: list_conj_qf)
 27.1515 -  with qe have cno_qf:"qfree (qe ?cno )" 
 27.1516 -    and noE: "Ifm bs (qe ?cno) = Ifm bs (E ?cno)" by blast+
 27.1517 -  from cno_qf yes_qf have qf: "qfree (CJNB qe p)" 
 27.1518 -    by (simp add: CJNB_def Let_def conj_qf split_def)
 27.1519 -  {fix bs
 27.1520 -    from conjuncts have "Ifm bs p = (\<forall>q\<in> set ?cjs. Ifm bs q)" by blast
 27.1521 -    also have "\<dots> = ((\<forall>q\<in> set ?yes. Ifm bs q) \<and> (\<forall>q\<in> set ?no. Ifm bs q))"
 27.1522 -      using partition_set[OF part] by auto
 27.1523 -    finally have "Ifm bs p = ((Ifm bs ?cyes) \<and> (Ifm bs ?cno))" using list_conj by simp}
 27.1524 -  hence "Ifm bs (E p) = (\<exists>x. (Ifm (x#bs) ?cyes) \<and> (Ifm (x#bs) ?cno))" by simp
 27.1525 -  also fix y have "\<dots> = (\<exists>x. (Ifm (y#bs) ?cyes) \<and> (Ifm (x#bs) ?cno))"
 27.1526 -    using bound0_I[OF yes_nb, where bs="bs" and b'="y"] by blast
 27.1527 -  also have "\<dots> = (Ifm bs (decr ?cyes) \<and> Ifm bs (E ?cno))"
 27.1528 -    by (auto simp add: decr[OF yes_nb])
 27.1529 -  also have "\<dots> = (Ifm bs (conj (decr ?cyes) (qe ?cno)))"
 27.1530 -    using qe[rule_format, OF no_qf] by auto
 27.1531 -  finally have "Ifm bs (E p) = Ifm bs (CJNB qe p)" 
 27.1532 -    by (simp add: Let_def CJNB_def split_def)
 27.1533 -  with qf show "qfree (CJNB qe p) \<and> Ifm bs (CJNB qe p) = Ifm bs (E p)" by blast
 27.1534 -qed
 27.1535 -
 27.1536 -consts qelim :: "fm \<Rightarrow> (fm \<Rightarrow> fm) \<Rightarrow> fm"
 27.1537 -recdef qelim "measure fmsize"
 27.1538 -  "qelim (E p) = (\<lambda> qe. DJ (CJNB qe) (qelim p qe))"
 27.1539 -  "qelim (A p) = (\<lambda> qe. not (qe ((qelim (NOT p) qe))))"
 27.1540 -  "qelim (NOT p) = (\<lambda> qe. not (qelim p qe))"
 27.1541 -  "qelim (And p q) = (\<lambda> qe. conj (qelim p qe) (qelim q qe))" 
 27.1542 -  "qelim (Or  p q) = (\<lambda> qe. disj (qelim p qe) (qelim q qe))" 
 27.1543 -  "qelim (Imp p q) = (\<lambda> qe. disj (qelim (NOT p) qe) (qelim q qe))"
 27.1544 -  "qelim (Iff p q) = (\<lambda> qe. iff (qelim p qe) (qelim q qe))"
 27.1545 -  "qelim p = (\<lambda> y. simpfm p)"
 27.1546 -
 27.1547 -lemma qelim_ci:
 27.1548 -  assumes qe_inv: "\<forall> bs p. qfree p \<longrightarrow> qfree (qe p) \<and> (Ifm bs (qe p) = Ifm bs (E p))"
 27.1549 -  shows "\<And> bs. qfree (qelim p qe) \<and> (Ifm bs (qelim p qe) = Ifm bs p)"
 27.1550 -using qe_inv DJ_qe[OF CJNB_qe[OF qe_inv]] 
 27.1551 -by(induct p rule: qelim.induct) 
 27.1552 -(auto simp del: simpfm.simps)
 27.1553 -
 27.1554 -
 27.1555 -text {* The @{text "\<int>"} Part *}
 27.1556 -text{* Linearity for fm where Bound 0 ranges over @{text "\<int>"} *}
 27.1557 -consts
 27.1558 -  zsplit0 :: "num \<Rightarrow> int \<times> num" (* splits the bounded from the unbounded part*)
 27.1559 -recdef zsplit0 "measure num_size"
 27.1560 -  "zsplit0 (C c) = (0,C c)"
 27.1561 -  "zsplit0 (Bound n) = (if n=0 then (1, C 0) else (0,Bound n))"
 27.1562 -  "zsplit0 (CN n c a) = zsplit0 (Add (Mul c (Bound n)) a)"
 27.1563 -  "zsplit0 (CF c a b) = zsplit0 (Add (Mul c (Floor a)) b)"
 27.1564 -  "zsplit0 (Neg a) = (let (i',a') =  zsplit0 a in (-i', Neg a'))"
 27.1565 -  "zsplit0 (Add a b) = (let (ia,a') =  zsplit0 a ; 
 27.1566 -                            (ib,b') =  zsplit0 b 
 27.1567 -                            in (ia+ib, Add a' b'))"
 27.1568 -  "zsplit0 (Sub a b) = (let (ia,a') =  zsplit0 a ; 
 27.1569 -                            (ib,b') =  zsplit0 b 
 27.1570 -                            in (ia-ib, Sub a' b'))"
 27.1571 -  "zsplit0 (Mul i a) = (let (i',a') =  zsplit0 a in (i*i', Mul i a'))"
 27.1572 -  "zsplit0 (Floor a) = (let (i',a') =  zsplit0 a in (i',Floor a'))"
 27.1573 -(hints simp add: Let_def)
 27.1574 -
 27.1575 -lemma zsplit0_I:
 27.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"
 27.1577 -  (is "\<And> n a. ?S t = (n,a) \<Longrightarrow> (?I x (CN 0 n a) = ?I x t) \<and> ?N a")
 27.1578 -proof(induct t rule: zsplit0.induct)
 27.1579 -  case (1 c n a) thus ?case by auto 
 27.1580 -next
 27.1581 -  case (2 m n a) thus ?case by (cases "m=0") auto
 27.1582 -next
 27.1583 -  case (3 n i a n a') thus ?case by auto
 27.1584 -next 
 27.1585 -  case (4 c a b n a') thus ?case by auto
 27.1586 -next
 27.1587 -  case (5 t n a)
 27.1588 -  let ?nt = "fst (zsplit0 t)"
 27.1589 -  let ?at = "snd (zsplit0 t)"
 27.1590 -  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Neg ?at \<and> n=-?nt" using prems 
 27.1591 -    by (simp add: Let_def split_def)
 27.1592 -  from abj prems  have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 27.1593 -  from th2[simplified] th[simplified] show ?case by simp
 27.1594 -next
 27.1595 -  case (6 s t n a)
 27.1596 -  let ?ns = "fst (zsplit0 s)"
 27.1597 -  let ?as = "snd (zsplit0 s)"
 27.1598 -  let ?nt = "fst (zsplit0 t)"
 27.1599 -  let ?at = "snd (zsplit0 t)"
 27.1600 -  have abjs: "zsplit0 s = (?ns,?as)" by simp 
 27.1601 -  moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp 
 27.1602 -  ultimately have th: "a=Add ?as ?at \<and> n=?ns + ?nt" using prems 
 27.1603 -    by (simp add: Let_def split_def)
 27.1604 -  from abjs[symmetric] have bluddy: "\<exists> x y. (x,y) = zsplit0 s" by blast
 27.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
 27.1606 -  with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 27.1607 -  from abjs prems  have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
 27.1608 -  from th3[simplified] th2[simplified] th[simplified] show ?case 
 27.1609 -    by (simp add: left_distrib)
 27.1610 -next
 27.1611 -  case (7 s t n a)
 27.1612 -  let ?ns = "fst (zsplit0 s)"
 27.1613 -  let ?as = "snd (zsplit0 s)"
 27.1614 -  let ?nt = "fst (zsplit0 t)"
 27.1615 -  let ?at = "snd (zsplit0 t)"
 27.1616 -  have abjs: "zsplit0 s = (?ns,?as)" by simp 
 27.1617 -  moreover have abjt:  "zsplit0 t = (?nt,?at)" by simp 
 27.1618 -  ultimately have th: "a=Sub ?as ?at \<and> n=?ns - ?nt" using prems 
 27.1619 -    by (simp add: Let_def split_def)
 27.1620 -  from abjs[symmetric] have bluddy: "\<exists> x y. (x,y) = zsplit0 s" by blast
 27.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
 27.1622 -  with bluddy abjt have th3: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 27.1623 -  from abjs prems  have th2: "(?I x (CN 0 ?ns ?as) = ?I x s) \<and> ?N ?as" by blast
 27.1624 -  from th3[simplified] th2[simplified] th[simplified] show ?case 
 27.1625 -    by (simp add: left_diff_distrib)
 27.1626 -next
 27.1627 -  case (8 i t n a)
 27.1628 -  let ?nt = "fst (zsplit0 t)"
 27.1629 -  let ?at = "snd (zsplit0 t)"
 27.1630 -  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a=Mul i ?at \<and> n=i*?nt" using prems 
 27.1631 -    by (simp add: Let_def split_def)
 27.1632 -  from abj prems  have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 27.1633 -  hence " ?I x (Mul i t) = (real i) * ?I x (CN 0 ?nt ?at)" by simp
 27.1634 -  also have "\<dots> = ?I x (CN 0 (i*?nt) (Mul i ?at))" by (simp add: right_distrib)
 27.1635 -  finally show ?case using th th2 by simp
 27.1636 -next
 27.1637 -  case (9 t n a)
 27.1638 -  let ?nt = "fst (zsplit0 t)"
 27.1639 -  let ?at = "snd (zsplit0 t)"
 27.1640 -  have abj: "zsplit0 t = (?nt,?at)" by simp hence th: "a= Floor ?at \<and> n=?nt" using prems 
 27.1641 -    by (simp add: Let_def split_def)
 27.1642 -  from abj prems  have th2: "(?I x (CN 0 ?nt ?at) = ?I x t) \<and> ?N ?at" by blast
 27.1643 -  hence na: "?N a" using th by simp
 27.1644 -  have th': "(real ?nt)*(real x) = real (?nt * x)" by simp
 27.1645 -  have "?I x (Floor t) = ?I x (Floor (CN 0 ?nt ?at))" using th2 by simp
 27.1646 -  also have "\<dots> = real (floor ((real ?nt)* real(x) + ?I x ?at))" by simp
 27.1647 -  also have "\<dots> = real (floor (?I x ?at + real (?nt* x)))" by (simp add: add_ac)
 27.1648 -  also have "\<dots> = real (floor (?I x ?at) + (?nt* x))" 
 27.1649 -    using floor_add[where x="?I x ?at" and a="?nt* x"] by simp 
 27.1650 -  also have "\<dots> = real (?nt)*(real x) + real (floor (?I x ?at))" by (simp add: add_ac)
 27.1651 -  finally have "?I x (Floor t) = ?I x (CN 0 n a)" using th by simp
 27.1652 -  with na show ?case by simp
 27.1653 -qed
 27.1654 -
 27.1655 -consts
 27.1656 -  iszlfm :: "fm \<Rightarrow> real list \<Rightarrow> bool"   (* Linearity test for fm *)
 27.1657 -  zlfm :: "fm \<Rightarrow> fm"       (* Linearity transformation for fm *)
 27.1658 -recdef iszlfm "measure size"
 27.1659 -  "iszlfm (And p q) = (\<lambda> bs. iszlfm p bs \<and> iszlfm q bs)" 
 27.1660 -  "iszlfm (Or p q) = (\<lambda> bs. iszlfm p bs \<and> iszlfm q bs)" 
 27.1661 -  "iszlfm (Eq  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 27.1662 -  "iszlfm (NEq (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 27.1663 -  "iszlfm (Lt  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 27.1664 -  "iszlfm (Le  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 27.1665 -  "iszlfm (Gt  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 27.1666 -  "iszlfm (Ge  (CN 0 c e)) = (\<lambda> bs. c>0 \<and> numbound0 e \<and> isint e bs)"
 27.1667 -  "iszlfm (Dvd i (CN 0 c e)) = 
 27.1668 -                 (\<lambda> bs. c>0 \<and> i>0 \<and> numbound0 e \<and> isint e bs)"
 27.1669 -  "iszlfm (NDvd i (CN 0 c e))= 
 27.1670 -                 (\<lambda> bs. c>0 \<and> i>0 \<and> numbound0 e \<and> isint e bs)"
 27.1671 -  "iszlfm p = (\<lambda> bs. isatom p \<and> (bound0 p))"
 27.1672 -
 27.1673 -lemma zlin_qfree: "iszlfm p bs \<Longrightarrow> qfree p"
 27.1674 -  by (induct p rule: iszlfm.induct) auto
 27.1675 -
 27.1676 -lemma iszlfm_gen:
 27.1677 -  assumes lp: "iszlfm p (x#bs)"
 27.1678 -  shows "\<forall> y. iszlfm p (y#bs)"
 27.1679 -proof
 27.1680 -  fix y
 27.1681 -  show "iszlfm p (y#bs)"
 27.1682 -    using lp
 27.1683 -  by(induct p rule: iszlfm.induct, simp_all add: numbound0_gen[rule_format, where x="x" and y="y"])
 27.1684 -qed
 27.1685 -
 27.1686 -lemma conj_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm q bs \<Longrightarrow> iszlfm (conj p q) bs"
 27.1687 -  using conj_def by (cases p,auto)
 27.1688 -lemma disj_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm q bs \<Longrightarrow> iszlfm (disj p q) bs"
 27.1689 -  using disj_def by (cases p,auto)
 27.1690 -lemma not_zl[simp]: "iszlfm p bs \<Longrightarrow> iszlfm (not p) bs"
 27.1691 -  by (induct p rule:iszlfm.induct ,auto)
 27.1692 -
 27.1693 -recdef zlfm "measure fmsize"
 27.1694 -  "zlfm (And p q) = conj (zlfm p) (zlfm q)"
 27.1695 -  "zlfm (Or p q) = disj (zlfm p) (zlfm q)"
 27.1696 -  "zlfm (Imp p q) = disj (zlfm (NOT p)) (zlfm q)"
 27.1697 -  "zlfm (Iff p q) = disj (conj (zlfm p) (zlfm q)) (conj (zlfm (NOT p)) (zlfm (NOT q)))"
 27.1698 -  "zlfm (Lt a) = (let (c,r) = zsplit0 a in 
 27.1699 -     if c=0 then Lt r else 
 27.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))) 
 27.1701 -     else Or (Gt (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))"
 27.1702 -  "zlfm (Le a) = (let (c,r) = zsplit0 a in 
 27.1703 -     if c=0 then Le r else 
 27.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))) 
 27.1705 -     else Or (Ge (CN 0 (-c) (Floor(Neg r)))) (And (Eq(CN 0 (-c) (Floor(Neg r)))) (Lt (Add (Floor (Neg r)) r))))"
 27.1706 -  "zlfm (Gt a) = (let (c,r) = zsplit0 a in 
 27.1707 -     if c=0 then Gt r else 
 27.1708 -     if c>0 then Or (Gt (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) 
 27.1709 -     else Or (Lt (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))"
 27.1710 -  "zlfm (Ge a) = (let (c,r) = zsplit0 a in 
 27.1711 -     if c=0 then Ge r else 
 27.1712 -     if c>0 then Or (Ge (CN 0 c (Floor r))) (And (Eq (CN 0 c (Floor r))) (Lt (Sub (Floor r) r))) 
 27.1713 -     else Or (Le (CN 0 (-c) (Neg (Floor r)))) (And (Eq(CN 0 (-c) (Neg (Floor r)))) (Lt (Sub (Floor r) r))))"
 27.1714 -  "zlfm (Eq a) = (let (c,r) = zsplit0 a in 
 27.1715 -              if c=0 then Eq r else 
 27.1716 -      if c>0 then (And (Eq (CN 0 c (Neg (Floor (Neg r))))) (Eq (Add (Floor (Neg r)) r)))
 27.1717 -      else (And (Eq (CN 0 (-c) (Floor (Neg r)))) (Eq (Add (Floor (Neg r)) r))))"
 27.1718 -  "zlfm (NEq a) = (let (c,r) = zsplit0 a in 
 27.1719 -              if c=0 then NEq r else 
 27.1720 -      if c>0 then (Or (NEq (CN 0 c (Neg (Floor (Neg r))))) (NEq (Add (Floor (Neg r)) r)))
 27.1721 -      else (Or (NEq (CN 0 (-c) (Floor (Neg r)))) (NEq (Add (Floor (Neg r)) r))))"
 27.1722 -  "zlfm (Dvd i a) = (if i=0 then zlfm (Eq a) 
 27.1723 -  else (let (c,r) = zsplit0 a in 
 27.1724 -              if c=0 then Dvd (abs i) r else 
 27.1725 -      if c>0 then And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 c (Floor r))) 
 27.1726 -      else And (Eq (Sub (Floor r) r)) (Dvd (abs i) (CN 0 (-c) (Neg (Floor r))))))"
 27.1727 -  "zlfm (NDvd i a) = (if i=0 then zlfm (NEq a) 
 27.1728 -  else (let (c,r) = zsplit0 a in 
 27.1729 -              if c=0 then NDvd (abs i) r else 
 27.1730 -      if c>0 then Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 c (Floor r))) 
 27.1731 -      else Or (NEq (Sub (Floor r) r)) (NDvd (abs i) (CN 0 (-c) (Neg (Floor r))))))"
 27.1732 -  "zlfm (NOT (And p q)) = disj (zlfm (NOT p)) (zlfm (NOT q))"
 27.1733 -  "zlfm (NOT (Or p q)) = conj (zlfm (NOT p)) (zlfm (NOT q))"
 27.1734 -  "zlfm (NOT (Imp p q)) = conj (zlfm p) (zlfm (NOT q))"
 27.1735 -  "zlfm (NOT (Iff p q)) = disj (conj(zlfm p) (zlfm(NOT q))) (conj (zlfm(NOT p)) (zlfm q))"
 27.1736 -  "zlfm (NOT (NOT p)) = zlfm p"
 27.1737 -  "zlfm (NOT T) = F"
 27.1738 -  "zlfm (NOT F) = T"
 27.1739 -  "zlfm (NOT (Lt a)) = zlfm (Ge a)"
 27.1740 -  "zlfm (NOT (Le a)) = zlfm (Gt a)"
 27.1741 -  "zlfm (NOT (Gt a)) = zlfm (Le a)"
 27.1742 -  "zlfm (NOT (Ge a)) = zlfm (Lt a)"
 27.1743 -  "zlfm (NOT (Eq a)) = zlfm (NEq a)"
 27.1744 -  "zlfm (NOT (NEq a)) = zlfm (Eq a)"
 27.1745 -  "zlfm (NOT (Dvd i a)) = zlfm (NDvd i a)"
 27.1746 -  "zlfm (NOT (NDvd i a)) = zlfm (Dvd i a)"
 27.1747 -  "zlfm p = p" (hints simp add: fmsize_pos)
 27.1748 -
 27.1749 -lemma split_int_less_real: 
 27.1750 -  "(real (a::int) < b) = (a < floor b \<or> (a = floor b \<and> real (floor b) < b))"
 27.1751 -proof( auto)
 27.1752 -  assume alb: "real a < b" and agb: "\<not> a < floor b"
 27.1753 -  from agb have "floor b \<le> a" by simp hence th: "b < real a + 1" by (simp only: floor_le_eq)
 27.1754 -  from floor_eq[OF alb th] show "a= floor b" by simp 
 27.1755 -next
 27.1756 -  assume alb: "a < floor b"
 27.1757 -  hence "real a < real (floor b)" by simp
 27.1758 -  moreover have "real (floor b) \<le> b" by simp ultimately show  "real a < b" by arith 
 27.1759 -qed
 27.1760 -
 27.1761 -lemma split_int_less_real': 
 27.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))"
 27.1763 -proof- 
 27.1764 -  have "(real a + b <0) = (real a < -b)" by arith
 27.1765 -  with split_int_less_real[where a="a" and b="-b"] show ?thesis by arith  
 27.1766 -qed
 27.1767 -
 27.1768 -lemma split_int_gt_real': 
 27.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))"
 27.1770 -proof- 
 27.1771 -  have th: "(real a + b >0) = (real (-a) + (-b)< 0)" by arith
 27.1772 -  show ?thesis using myless[rule_format, where b="real (floor b)"] 
 27.1773 -    by (simp only:th split_int_less_real'[where a="-a" and b="-b"]) 
 27.1774 -    (simp add: ring_simps diff_def[symmetric],arith)
 27.1775 -qed
 27.1776 -
 27.1777 -lemma split_int_le_real: 
 27.1778 -  "(real (a::int) \<le> b) = (a \<le> floor b \<or> (a = floor b \<and> real (floor b) < b))"
 27.1779 -proof( auto)
 27.1780 -  assume alb: "real a \<le> b" and agb: "\<not> a \<le> floor b"
 27.1781 -  from alb have "floor (real a) \<le> floor b " by (simp only: floor_mono2) 
 27.1782 -  hence "a \<le> floor b" by simp with agb show "False" by simp
 27.1783 -next
 27.1784 -  assume alb: "a \<le> floor b"
 27.1785 -  hence "real a \<le> real (floor b)" by (simp only: floor_mono2)
 27.1786 -  also have "\<dots>\<le> b" by simp  finally show  "real a \<le> b" . 
 27.1787 -qed
 27.1788 -
 27.1789 -lemma split_int_le_real': 
 27.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))"
 27.1791 -proof- 
 27.1792 -  have "(real a + b \<le>0) = (real a \<le> -b)" by arith
 27.1793 -  with split_int_le_real[where a="a" and b="-b"] show ?thesis by arith  
 27.1794 -qed
 27.1795 -
 27.1796 -lemma split_int_ge_real': 
 27.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))"
 27.1798 -proof- 
 27.1799 -  have th: "(real a + b \<ge>0) = (real (-a) + (-b) \<le> 0)" by arith
 27.1800 -  show ?thesis by (simp only: th split_int_le_real'[where a="-a" and b="-b"])
 27.1801 -    (simp add: ring_simps diff_def[symmetric],arith)
 27.1802 -qed
 27.1803 -
 27.1804 -lemma split_int_eq_real: "(real (a::int) = b) = ( a = floor b \<and> b = real (floor b))" (is "?l = ?r")
 27.1805 -by auto
 27.1806 -
 27.1807 -lemma split_int_eq_real': "(real (a::int) + b = 0) = ( a - floor (-b) = 0 \<and> real (floor (-b)) + b = 0)" (is "?l = ?r")
 27.1808 -proof-
 27.1809 -  have "?l = (real a = -b)" by arith
 27.1810 -  with split_int_eq_real[where a="a" and b="-b"] show ?thesis by simp arith
 27.1811 -qed
 27.1812 -
 27.1813 -lemma zlfm_I:
 27.1814 -  assumes qfp: "qfree p"
 27.1815 -  shows "(Ifm (real i #bs) (zlfm p) = Ifm (real i# bs) p) \<and> iszlfm (zlfm p) (real (i::int) #bs)"
 27.1816 -  (is "(?I (?l p) = ?I p) \<and> ?L (?l p)")
 27.1817 -using qfp
 27.1818 -proof(induct p rule: zlfm.induct)
 27.1819 -  case (5 a) 
 27.1820 -  let ?c = "fst (zsplit0 a)"
 27.1821 -  let ?r = "snd (zsplit0 a)"
 27.1822 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1823 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1824 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1825 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.1826 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 27.1827 -  moreover
 27.1828 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1829 -      by (cases "?r", simp_all add: Let_def split_def,case_tac "nat", simp_all)}
 27.1830 -  moreover
 27.1831 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Lt a))" 
 27.1832 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1833 -    have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1835 -    finally have ?case using l by simp}
 27.1836 -  moreover
 27.1837 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Lt a))" 
 27.1838 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1839 -    have "?I (Lt a) = (real (?c * i) + (?N ?r) < 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1841 -    finally have ?case using l by simp}
 27.1842 -  ultimately show ?case by blast
 27.1843 -next
 27.1844 -  case (6 a)
 27.1845 -  let ?c = "fst (zsplit0 a)"
 27.1846 -  let ?r = "snd (zsplit0 a)"
 27.1847 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1848 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1849 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1850 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.1851 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 27.1852 -  moreover
 27.1853 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1854 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat",simp_all)}
 27.1855 -  moreover
 27.1856 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Le a))" 
 27.1857 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1858 -    have "?I (Le a) = (real (?c * i) + (?N ?r) \<le> 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1860 -    finally have ?case using l by simp}
 27.1861 -  moreover
 27.1862 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Le a))" 
 27.1863 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1864 -    have "?I (Le a) = (real (?c * i) + (?N ?r) \<le> 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1866 -    finally have ?case using l by simp}
 27.1867 -  ultimately show ?case by blast
 27.1868 -next
 27.1869 -  case (7 a) 
 27.1870 -  let ?c = "fst (zsplit0 a)"
 27.1871 -  let ?r = "snd (zsplit0 a)"
 27.1872 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1873 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1874 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1875 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.1876 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 27.1877 -  moreover
 27.1878 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1879 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 27.1880 -  moreover
 27.1881 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Gt a))" 
 27.1882 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1883 -    have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1885 -    finally have ?case using l by simp}
 27.1886 -  moreover
 27.1887 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Gt a))" 
 27.1888 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1889 -    have "?I (Gt a) = (real (?c * i) + (?N ?r) > 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1891 -    finally have ?case using l by simp}
 27.1892 -  ultimately show ?case by blast
 27.1893 -next
 27.1894 -  case (8 a)
 27.1895 -   let ?c = "fst (zsplit0 a)"
 27.1896 -  let ?r = "snd (zsplit0 a)"
 27.1897 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1898 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1899 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1900 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.1901 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 27.1902 -  moreover
 27.1903 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1904 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 27.1905 -  moreover
 27.1906 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Ge a))" 
 27.1907 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1908 -    have "?I (Ge a) = (real (?c * i) + (?N ?r) \<ge> 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1910 -    finally have ?case using l by simp}
 27.1911 -  moreover
 27.1912 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Ge a))" 
 27.1913 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1914 -    have "?I (Ge a) = (real (?c * i) + (?N ?r) \<ge> 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1916 -    finally have ?case using l by simp}
 27.1917 -  ultimately show ?case by blast
 27.1918 -next
 27.1919 -  case (9 a)
 27.1920 -  let ?c = "fst (zsplit0 a)"
 27.1921 -  let ?r = "snd (zsplit0 a)"
 27.1922 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1923 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1924 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1925 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.1926 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 27.1927 -  moreover
 27.1928 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1929 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 27.1930 -  moreover
 27.1931 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Eq a))" 
 27.1932 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1933 -    have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1935 -    finally have ?case using l by simp}
 27.1936 -  moreover
 27.1937 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (Eq a))" 
 27.1938 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1939 -    have "?I (Eq a) = (real (?c * i) + (?N ?r) = 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1941 -    finally have ?case using l by simp}
 27.1942 -  ultimately show ?case by blast
 27.1943 -next
 27.1944 -  case (10 a)
 27.1945 -  let ?c = "fst (zsplit0 a)"
 27.1946 -  let ?r = "snd (zsplit0 a)"
 27.1947 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1948 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1949 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1950 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.1951 -  have "?c = 0 \<or> (?c >0 \<and> ?c\<noteq>0) \<or> (?c<0 \<and> ?c\<noteq>0)" by arith
 27.1952 -  moreover
 27.1953 -  {assume "?c=0" hence ?case using zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1954 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 27.1955 -  moreover
 27.1956 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (NEq a))" 
 27.1957 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1958 -    have "?I (NEq a) = (real (?c * i) + (?N ?r) \<noteq> 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1960 -    finally have ?case using l by simp}
 27.1961 -  moreover
 27.1962 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" hence l: "?L (?l (NEq a))" 
 27.1963 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1964 -    have "?I (NEq a) = (real (?c * i) + (?N ?r) \<noteq> 0)" using Ia by (simp add: Let_def split_def)
 27.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)
 27.1966 -    finally have ?case using l by simp}
 27.1967 -  ultimately show ?case by blast
 27.1968 -next
 27.1969 -  case (11 j a)
 27.1970 -  let ?c = "fst (zsplit0 a)"
 27.1971 -  let ?r = "snd (zsplit0 a)"
 27.1972 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.1973 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.1974 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.1975 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.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
 27.1977 -  moreover
 27.1978 -  {assume "j=0" hence z: "zlfm (Dvd j a) = (zlfm (Eq a))" by (simp add: Let_def) 
 27.1979 -    hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)}
 27.1980 -  moreover
 27.1981 -  {assume "?c=0" and "j\<noteq>0" hence ?case 
 27.1982 -      using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"]
 27.1983 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 27.1984 -  moreover
 27.1985 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))" 
 27.1986 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.1987 -    have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" 
 27.1988 -      using Ia by (simp add: Let_def split_def)
 27.1989 -    also have "\<dots> = (real (abs j) rdvd real (?c*i) + (?N ?r))" 
 27.1990 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 27.1991 -    also have "\<dots> = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 27.1992 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" 
 27.1993 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 27.1994 -    also have "\<dots> = (?I (?l (Dvd j a)))" using cp cnz jnz  
 27.1995 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 27.1996 -	del: real_of_int_mult) (auto simp add: add_ac)
 27.1997 -    finally have ?case using l jnz  by simp }
 27.1998 -  moreover
 27.1999 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (Dvd j a))" 
 27.2000 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.2001 -    have "?I (Dvd j a) = (real j rdvd (real (?c * i) + (?N ?r)))" 
 27.2002 -      using Ia by (simp add: Let_def split_def)
 27.2003 -    also have "\<dots> = (real (abs j) rdvd real (?c*i) + (?N ?r))" 
 27.2004 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 27.2005 -    also have "\<dots> = ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 27.2006 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r))))" 
 27.2007 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 27.2008 -    also have "\<dots> = (?I (?l (Dvd j a)))" using cn cnz jnz
 27.2009 -      using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric]
 27.2010 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 27.2011 -	del: real_of_int_mult) (auto simp add: add_ac)
 27.2012 -    finally have ?case using l jnz by blast }
 27.2013 -  ultimately show ?case by blast
 27.2014 -next
 27.2015 -  case (12 j a)
 27.2016 -  let ?c = "fst (zsplit0 a)"
 27.2017 -  let ?r = "snd (zsplit0 a)"
 27.2018 -  have spl: "zsplit0 a = (?c,?r)" by simp
 27.2019 -  from zsplit0_I[OF spl, where x="i" and bs="bs"] 
 27.2020 -  have Ia:"Inum (real i # bs) a = Inum (real i #bs) (CN 0 ?c ?r)" and nb: "numbound0 ?r" by auto 
 27.2021 -  let ?N = "\<lambda> t. Inum (real i#bs) t"
 27.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
 27.2023 -  moreover
 27.2024 -  {assume "j=0" hence z: "zlfm (NDvd j a) = (zlfm (NEq a))" by (simp add: Let_def) 
 27.2025 -    hence ?case using prems by (simp del: zlfm.simps add: rdvd_left_0_eq)}
 27.2026 -  moreover
 27.2027 -  {assume "?c=0" and "j\<noteq>0" hence ?case 
 27.2028 -      using zsplit0_I[OF spl, where x="i" and bs="bs"] rdvd_abs1[where d="j"]
 27.2029 -      by (cases "?r", simp_all add: Let_def split_def, case_tac "nat", simp_all)}
 27.2030 -  moreover
 27.2031 -  {assume cp: "?c > 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (NDvd j a))" 
 27.2032 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.2033 -    have "?I (NDvd j a) = (\<not> (real j rdvd (real (?c * i) + (?N ?r))))" 
 27.2034 -      using Ia by (simp add: Let_def split_def)
 27.2035 -    also have "\<dots> = (\<not> (real (abs j) rdvd real (?c*i) + (?N ?r)))" 
 27.2036 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 27.2037 -    also have "\<dots> = (\<not> ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 27.2038 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" 
 27.2039 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 27.2040 -    also have "\<dots> = (?I (?l (NDvd j a)))" using cp cnz jnz  
 27.2041 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 27.2042 -	del: real_of_int_mult) (auto simp add: add_ac)
 27.2043 -    finally have ?case using l jnz  by simp }
 27.2044 -  moreover
 27.2045 -  {assume cn: "?c < 0" and cnz: "?c\<noteq>0" and jnz: "j\<noteq>0" hence l: "?L (?l (NDvd j a))" 
 27.2046 -      by (simp add: nb Let_def split_def isint_Floor isint_neg)
 27.2047 -    have "?I (NDvd j a) = (\<not> (real j rdvd (real (?c * i) + (?N ?r))))" 
 27.2048 -      using Ia by (simp add: Let_def split_def)
 27.2049 -    also have "\<dots> = (\<not> (real (abs j) rdvd real (?c*i) + (?N ?r)))" 
 27.2050 -      by (simp only: rdvd_abs1[where d="j" and t="real (?c*i) + ?N ?r", symmetric]) simp
 27.2051 -    also have "\<dots> = (\<not> ((abs j) dvd (floor ((?N ?r) + real (?c*i))) \<and> 
 27.2052 -       (real (floor ((?N ?r) + real (?c*i))) = (real (?c*i) + (?N ?r)))))" 
 27.2053 -      by(simp only: int_rdvd_real[where i="abs j" and x="real (?c*i) + (?N ?r)"]) (simp only: add_ac)
 27.2054 -    also have "\<dots> = (?I (?l (NDvd j a)))" using cn cnz jnz
 27.2055 -      using rdvd_minus [where d="abs j" and t="real (?c*i + floor (?N ?r))", simplified, symmetric]
 27.2056 -      by (simp add: Let_def split_def int_rdvd_iff[symmetric]  
 27.2057 -	del: real_of_int_mult) (auto simp add: add_ac)
 27.2058 -    finally have ?case using l jnz by blast }
 27.2059 -  ultimately show ?case by blast
 27.2060 -qed auto
 27.2061 -
 27.2062 -text{* plusinf : Virtual substitution of @{text "+\<infinity>"}
 27.2063 -       minusinf: Virtual substitution of @{text "-\<infinity>"}
 27.2064 -       @{text "\<delta>"} Compute lcm @{text "d| Dvd d  c*x+t \<in> p"}
 27.2065 -       @{text "d\<delta>"} checks if a given l divides all the ds above*}
 27.2066 -
 27.2067 -consts 
 27.2068 -  plusinf:: "fm \<Rightarrow> fm" 
 27.2069 -  minusinf:: "fm \<Rightarrow> fm"
 27.2070 -  \<delta> :: "fm \<Rightarrow> int" 
 27.2071 -  d\<delta> :: "fm \<Rightarrow> int \<Rightarrow> bool"
 27.2072 -
 27.2073 -recdef minusinf "measure size"
 27.2074 -  "minusinf (And p q) = conj (minusinf p) (minusinf q)" 
 27.2075 -  "minusinf (Or p q) = disj (minusinf p) (minusinf q)" 
 27.2076 -  "minusinf (Eq  (CN 0 c e)) = F"
 27.2077 -  "minusinf (NEq (CN 0 c e)) = T"
 27.2078 -  "minusinf (Lt  (CN 0 c e)) = T"
 27.2079 -  "minusinf (Le  (CN 0 c e)) = T"
 27.2080 -  "minusinf (Gt  (CN 0 c e)) = F"
 27.2081 -  "minusinf (Ge  (CN 0 c e)) = F"
 27.2082 -  "minusinf p = p"
 27.2083 -
 27.2084 -lemma minusinf_qfree: "qfree p \<Longrightarrow> qfree (minusinf p)"
 27.2085 -  by (induct p rule: minusinf.induct, auto)
 27.2086 -
 27.2087 -recdef plusinf "measure size"
 27.2088 -  "plusinf (And p q) = conj (plusinf p) (plusinf q)" 
 27.2089 -  "plusinf (Or p q) = disj (plusinf p) (plusinf q)" 
 27.2090 -  "plusinf (Eq  (CN 0 c e)) = F"
 27.2091 -  "plusinf (NEq (CN 0 c e)) = T"
 27.2092 -  "plusinf (Lt  (CN 0 c e)) = F"
 27.2093 -  "plusinf (Le  (CN 0 c e)) = F"
 27.2094 -  "plusinf (Gt  (CN 0 c e)) = T"
 27.2095 -  "plusinf (Ge  (CN 0 c e)) = T"
 27.2096 -  "plusinf p = p"
 27.2097 -
 27.2098 -recdef \<delta> "measure size"
 27.2099 -  "\<delta> (And p q) = zlcm (\<delta> p) (\<delta> q)" 
 27.2100 -  "\<delta> (Or p q) = zlcm (\<delta> p) (\<delta> q)" 
 27.2101 -  "\<delta> (Dvd i (CN 0 c e)) = i"
 27.2102 -  "\<delta> (NDvd i (CN 0 c e)) = i"
 27.2103 -  "\<delta> p = 1"
 27.2104 -
 27.2105 -recdef d\<delta> "measure size"
 27.2106 -  "d\<delta> (And p q) = (\<lambda> d. d\<delta> p d \<and> d\<delta> q d)" 
 27.2107 -  "d\<delta> (Or p q) = (\<lambda> d. d\<delta> p d \<and> d\<delta> q d)" 
 27.2108 -  "d\<delta> (Dvd i (CN 0 c e)) = (\<lambda> d. i dvd d)"
 27.2109 -  "d\<delta> (NDvd i (CN 0 c e)) = (\<lambda> d. i dvd d)"
 27.2110 -  "d\<delta> p = (\<lambda> d. True)"
 27.2111 -
 27.2112 -lemma delta_mono: 
 27.2113 -  assumes lin: "iszlfm p bs"
 27.2114 -  and d: "d dvd d'"
 27.2115 -  and ad: "d\<delta> p d"
 27.2116 -  shows "d\<delta> p d'"
 27.2117 -  using lin ad d
 27.2118 -proof(induct p rule: iszlfm.induct)
 27.2119 -  case (9 i c e)  thus ?case using d
 27.2120 -    by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"])
 27.2121 -next
 27.2122 -  case (10 i c e) thus ?case using d
 27.2123 -    by (simp add: zdvd_trans[where m="i" and n="d" and k="d'"])
 27.2124 -qed simp_all
 27.2125 -
 27.2126 -lemma \<delta> : assumes lin:"iszlfm p bs"
 27.2127 -  shows "d\<delta> p (\<delta> p) \<and> \<delta> p >0"
 27.2128 -using lin
 27.2129 -proof (induct p rule: iszlfm.induct)
 27.2130 -  case (1 p q) 
 27.2131 -  let ?d = "\<delta> (And p q)"
 27.2132 -  from prems zlcm_pos have dp: "?d >0" by simp
 27.2133 -  have d1: "\<delta> p dvd \<delta> (And p q)" using prems by simp 
 27.2134 -   hence th: "d\<delta> p ?d" 
 27.2135 -     using delta_mono prems by (auto simp del: dvd_zlcm_self1)
 27.2136 -  have "\<delta> q dvd \<delta> (And p q)" using prems  by simp 
 27.2137 -  hence th': "d\<delta> q ?d" using delta_mono prems by (auto simp del: dvd_zlcm_self2)
 27.2138 -  from th th' dp show ?case by simp 
 27.2139 -next
 27.2140 -  case (2 p q)  
 27.2141 -  let ?d = "\<delta> (And p q)"
 27.2142 -  from prems zlcm_pos have dp: "?d >0" by simp
 27.2143 -  have "\<delta> p dvd \<delta> (And p q)" using prems by simp hence th: "d\<delta> p ?d" using delta_mono prems 
 27.2144 -    by (auto simp del: dvd_zlcm_self1)
 27.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)
 27.2146 -  from th th' dp show ?case by simp 
 27.2147 -qed simp_all
 27.2148 -
 27.2149 -
 27.2150 -lemma minusinf_inf:
 27.2151 -  assumes linp: "iszlfm p (a # bs)"
 27.2152 -  shows "\<exists> (z::int). \<forall> x < z. Ifm ((real x)#bs) (minusinf p) = Ifm ((real x)#bs) p"
 27.2153 -  (is "?P p" is "\<exists> (z::int). \<forall> x < z. ?I x (?M p) = ?I x p")
 27.2154 -using linp
 27.2155 -proof (induct p rule: minusinf.induct)
 27.2156 -  case (1 f g)
 27.2157 -  from prems have "?P f" by simp
 27.2158 -  then obtain z1 where z1_def: "\<forall> x < z1. ?I x (?M f) = ?I x f" by blast
 27.2159 -  from prems have "?P g" by simp
 27.2160 -  then obtain z2 where z2_def: "\<forall> x < z2. ?I x (?M g) = ?I x g" by blast
 27.2161 -  let ?z = "min z1 z2"
 27.2162 -  from z1_def z2_def have "\<forall> x < ?z. ?I x (?M (And f g)) = ?I x (And f g)" by simp
 27.2163 -  thus ?case by blast
 27.2164 -next
 27.2165 -  case (2 f g)   from prems have "?P f" by simp
 27.2166 -  then obtain z1 where z1_def: "\<forall> x < z1. ?I x (?M f) = ?I x f" by blast
 27.2167 -  from prems have "?P g" by simp
 27.2168 -  then obtain z2 where z2_def: "\<forall> x < z2. ?I x (?M g) = ?I x g" by blast
 27.2169 -  let ?z = "min z1 z2"
 27.2170 -  from z1_def z2_def have "\<forall> x < ?z. ?I x (?M (Or f g)) = ?I x (Or f g)" by simp
 27.2171 -  thus ?case by blast
 27.2172 -next
 27.2173 -  case (3 c e) 
 27.2174 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 27.2175 -  from prems have nbe: "numbound0 e" by simp
 27.2176 -  fix y
 27.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))"
 27.2178 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 27.2179 -    fix x
 27.2180 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 27.2181 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 27.2182 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 27.2183 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 27.2184 -    hence "real c * real x + Inum (y # bs) e \<noteq> 0"using rcpos  by simp
 27.2185 -    thus "real c * real x + Inum (real x # bs) e \<noteq> 0" 
 27.2186 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"]  by simp
 27.2187 -  qed
 27.2188 -  thus ?case by blast
 27.2189 -next
 27.2190 -  case (4 c e) 
 27.2191 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 27.2192 -  from prems have nbe: "numbound0 e" by simp
 27.2193 -  fix y
 27.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))"
 27.2195 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 27.2196 -    fix x
 27.2197 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 27.2198 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 27.2199 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 27.2200 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 27.2201 -    hence "real c * real x + Inum (y # bs) e \<noteq> 0"using rcpos  by simp
 27.2202 -    thus "real c * real x + Inum (real x # bs) e \<noteq> 0" 
 27.2203 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"]  by simp
 27.2204 -  qed
 27.2205 -  thus ?case by blast
 27.2206 -next
 27.2207 -  case (5 c e) 
 27.2208 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 27.2209 -  from prems have nbe: "numbound0 e" by simp
 27.2210 -  fix y
 27.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))"
 27.2212 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 27.2213 -    fix x
 27.2214 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 27.2215 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 27.2216 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 27.2217 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 27.2218 -    thus "real c * real x + Inum (real x # bs) e < 0" 
 27.2219 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 27.2220 -  qed
 27.2221 -  thus ?case by blast
 27.2222 -next
 27.2223 -  case (6 c e) 
 27.2224 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 27.2225 -  from prems have nbe: "numbound0 e" by simp
 27.2226 -  fix y
 27.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))"
 27.2228 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 27.2229 -    fix x
 27.2230 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 27.2231 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 27.2232 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 27.2233 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 27.2234 -    thus "real c * real x + Inum (real x # bs) e \<le> 0" 
 27.2235 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 27.2236 -  qed
 27.2237 -  thus ?case by blast
 27.2238 -next
 27.2239 -  case (7 c e) 
 27.2240 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 27.2241 -  from prems have nbe: "numbound0 e" by simp
 27.2242 -  fix y
 27.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))"
 27.2244 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 27.2245 -    fix x
 27.2246 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 27.2247 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 27.2248 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 27.2249 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 27.2250 -    thus "\<not> (real c * real x + Inum (real x # bs) e>0)" 
 27.2251 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 27.2252 -  qed
 27.2253 -  thus ?case by blast
 27.2254 -next
 27.2255 -  case (8 c e) 
 27.2256 -  from prems have "c > 0" by simp hence rcpos: "real c > 0" by simp
 27.2257 -  from prems have nbe: "numbound0 e" by simp
 27.2258 -  fix y
 27.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))"
 27.2260 -  proof (simp add: less_floor_eq , rule allI, rule impI) 
 27.2261 -    fix x
 27.2262 -    assume A: "real x + (1\<Colon>real) \<le> - (Inum (y # bs) e / real c)"
 27.2263 -    hence th1:"real x < - (Inum (y # bs) e / real c)" by simp
 27.2264 -    with rcpos  have "(real c)*(real  x) < (real c)*(- (Inum (y # bs) e / real c))"
 27.2265 -      by (simp only:  real_mult_less_mono2[OF rcpos th1])
 27.2266 -    thus "\<not> real c * real x + Inum (real x # bs) e \<ge> 0" 
 27.2267 -      using numbound0_I[OF nbe, where b="y" and bs="bs" and b'="real x"] rcpos by simp
 27.2268 -  qed
 27.2269 -  thus ?case by blast
 27.2270 -qed simp_all
 27.2271 -
 27.2272 -lemma minusinf_repeats:
 27.2273 -  assumes d: "d\<delta> p d" and linp: "iszlfm p (a # bs)"
 27.2274 -  shows "Ifm ((real(x - k*d))#bs) (minusinf p) = Ifm (real x #bs) (minusinf p)"
 27.2275 -using linp d
 27.2276 -proof(induct p rule: iszlfm.induct) 
 27.2277 -  case (9 i c e) hence nbe: "numbound0 e"  and id: "i dvd d" by simp+
 27.2278 -    hence "\<exists> k. d=i*k" by (simp add: dvd_def)
 27.2279 -    then obtain "di" where di_def: "d=i*di" by blast
 27.2280 -    show ?case 
 27.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)
 27.2282 -      assume 
 27.2283 -	"real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e"
 27.2284 -      (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt")
 27.2285 -      hence "\<exists> (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def)
 27.2286 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" 
 27.2287 -	by (simp add: ring_simps di_def)
 27.2288 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))"
 27.2289 -	by (simp add: ring_simps)
 27.2290 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast
 27.2291 -      thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp
 27.2292 -    next
 27.2293 -      assume 
 27.2294 -	"real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e")
 27.2295 -      hence "\<exists> (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def)
 27.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
 27.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)
 27.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)
 27.2299 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)"
 27.2300 -	by blast
 27.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
 27.2302 -    qed
 27.2303 -next
 27.2304 -  case (10 i c e) hence nbe: "numbound0 e"  and id: "i dvd d" by simp+
 27.2305 -    hence "\<exists> k. d=i*k" by (simp add: dvd_def)
 27.2306 -    then obtain "di" where di_def: "d=i*di" by blast
 27.2307 -    show ?case 
 27.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)
 27.2309 -      assume 
 27.2310 -	"real i rdvd real c * real x - real c * (real k * real d) + Inum (real x # bs) e"
 27.2311 -      (is "?ri rdvd ?rc*?rx - ?rc*(?rk*?rd) + ?I x e" is "?ri rdvd ?rt")
 27.2312 -      hence "\<exists> (l::int). ?rt = ?ri * (real l)" by (simp add: rdvd_def)
 27.2313 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real l)+?rc*(?rk * (real i) * (real di))" 
 27.2314 -	by (simp add: ring_simps di_def)
 27.2315 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri*(real (l + c*k*di))"
 27.2316 -	by (simp add: ring_simps)
 27.2317 -      hence "\<exists> (l::int). ?rc*?rx+ ?I x e = ?ri* (real l)" by blast
 27.2318 -      thus "real i rdvd real c * real x + Inum (real x # bs) e" using rdvd_def by simp
 27.2319 -    next
 27.2320 -      assume 
 27.2321 -	"real i rdvd real c * real x + Inum (real x # bs) e" (is "?ri rdvd ?rc*?rx+?e")
 27.2322 -      hence "\<exists> (l::int). ?rc*?rx+?e = ?ri * (real l)" by (simp add: rdvd_def)
 27.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
 27.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)
 27.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)
 27.2326 -      hence "\<exists> (l::int). ?rc*?rx - real c * (real k * real d) +?e = ?ri * (real l)"
 27.2327 -	by blast
 27.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
 27.2329 -    qed
 27.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)
 27.2331 -
 27.2332 -lemma minusinf_ex:
 27.2333 -  assumes lin: "iszlfm p (real (a::int) #bs)"
 27.2334 -  and exmi: "\<exists> (x::int). Ifm (real x#bs) (minusinf p)" (is "\<exists> x. ?P1 x")
 27.2335 -  shows "\<exists> (x::int). Ifm (real x#bs) p" (is "\<exists> x. ?P x")
 27.2336 -proof-
 27.2337 -  let ?d = "\<delta> p"
 27.2338 -  from \<delta> [OF lin] have dpos: "?d >0" by simp
 27.2339 -  from \<delta> [OF lin] have alld: "d\<delta> p ?d" by simp
 27.2340 -  from minusinf_repeats[OF alld lin] have th1:"\<forall> x k. ?P1 x = ?P1 (x - (k * ?d))" by simp
 27.2341 -  from minusinf_inf[OF lin] have th2:"\<exists> z. \<forall> x. x<z \<longrightarrow> (?P x = ?P1 x)" by blast
 27.2342 -  from minusinfinity [OF dpos th1 th2] exmi show ?thesis by blast
 27.2343 -qed
 27.2344 -
 27.2345 -lemma minusinf_bex:
 27.2346 -  assumes lin: "iszlfm p (real (a::int) #bs)"
 27.2347 -  shows "(\<exists> (x::int). Ifm (real x#bs) (minusinf p)) = 
 27.2348 -         (\<exists> (x::int)\<in> {1..\<delta> p}. Ifm (real x#bs) (minusinf p))"
 27.2349 -  (is "(\<exists> x. ?P x) = _")
 27.2350 -proof-
 27.2351 -  let ?d = "\<delta> p"
 27.2352 -  from \<delta> [OF lin] have dpos: "?d >0" by simp
 27.2353 -  from \<delta> [OF lin] have alld: "d\<delta> p ?d" by simp
 27.2354 -  from minusinf_repeats[OF alld lin] have th1:"\<forall> x k. ?P x = ?P (x - (k * ?d))" by simp
 27.2355 -  from periodic_finite_ex[OF dpos th1] show ?thesis by blast
 27.2356 -qed
 27.2357 -
 27.2358 -lemma dvd1_eq1: "x >0 \<Longrightarrow> (x::int) dvd 1 = (x = 1)" by auto
 27.2359 -
 27.2360 -consts 
 27.2361 -  a\<beta> :: "fm \<Rightarrow> int \<Rightarrow> fm" (* adjusts the coeffitients of a formula *)
 27.2362 -  d\<beta> :: "fm \<Rightarrow> int \<Rightarrow> bool" (* tests if all coeffs c of c divide a given l*)
 27.2363 -  \<zeta>  :: "fm \<Rightarrow> int" (* computes the lcm of all coefficients of x*)
 27.2364 -  \<beta> :: "fm \<Rightarrow> num list"
 27.2365 -  \<alpha> :: "fm \<Rightarrow> num list"
 27.2366 -
 27.2367 -recdef a\<beta> "measure size"
 27.2368 -  "a\<beta> (And p q) = (\<lambda> k. And (a\<beta> p k) (a\<beta> q k))" 
 27.2369 -  "a\<beta> (Or p q) = (\<lambda> k. Or (a\<beta> p k) (a\<beta> q k))" 
 27.2370 -  "a\<beta> (Eq  (CN 0 c e)) = (\<lambda> k. Eq (CN 0 1 (Mul (k div c) e)))"
 27.2371 -  "a\<beta> (NEq (CN 0 c e)) = (\<lambda> k. NEq (CN 0 1 (Mul (k div c) e)))"
 27.2372 -  "a\<beta> (Lt  (CN 0 c e)) = (\<lambda> k. Lt (CN 0 1 (Mul (k div c) e)))"
 27.2373 -  "a\<beta> (Le  (CN 0 c e)) = (\<lambda> k. Le (CN 0 1 (Mul (k div c) e)))"
 27.2374 -  "a\<beta> (Gt  (CN 0 c e)) = (\<lambda> k. Gt (CN 0 1 (Mul (k div c) e)))"
 27.2375 -  "a\<beta> (Ge  (CN 0 c e)) = (\<lambda> k. Ge (CN 0 1 (Mul (k div c) e)))"
 27.2376 -  "a\<beta> (Dvd i (CN 0 c e)) =(\<lambda> k. Dvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))"
 27.2377 -  "a\<beta> (NDvd i (CN 0 c e))=(\<lambda> k. NDvd ((k div c)*i) (CN 0 1 (Mul (k div c) e)))"
 27.2378 -  "a\<beta> p = (\<lambda> k. p)"
 27.2379 -
 27.2380 -recdef d\<beta> "measure size"
 27.2381 -  "d\<beta> (And p q) = (\<lambda> k. (d\<beta> p k) \<and> (d\<beta> q k))" 
 27.2382 -  "d\<beta> (Or p q) = (\<lambda> k. (d\<beta> p k) \<and> (d\<beta> q k))" 
 27.2383 -  "d\<beta> (Eq  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 27.2384 -  "d\<beta> (NEq (CN 0 c e)) = (\<lambda> k. c dvd k)"
 27.2385 -  "d\<beta> (Lt  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 27.2386 -  "d\<beta> (Le  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 27.2387 -  "d\<beta> (Gt  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 27.2388 -  "d\<beta> (Ge  (CN 0 c e)) = (\<lambda> k. c dvd k)"
 27.2389 -  "d\<beta> (Dvd i (CN 0 c e)) =(\<lambda> k. c dvd k)"
 27.2390 -  "d\<beta> (NDvd i (CN 0 c e))=(\<lambda> k. c dvd k)"
 27.2391 -  "d\<beta> p = (\<lambda> k. True)"
 27.2392 -
 27.2393 -recdef \<zeta> "measure size"
 27.2394 -  "\<zeta> (And p q) = zlcm (\<zeta> p) (\<zeta> q)" 
 27.2395 -  "\<zeta> (Or p q) = zlcm (\<zeta> p) (\<zeta> q)" 
 27.2396 -  "\<zeta> (Eq  (CN 0 c e)) = c"
 27.2397 -  "\<zeta> (NEq (CN 0 c e)) = c"
 27.2398 -  "\<zeta> (Lt  (CN 0 c e)) = c"
 27.2399 -  "\<zeta> (Le  (CN 0 c e)) = c"
 27.2400 -  "\<zeta> (Gt  (CN 0 c e)) = c"
 27.2401 -  "\<zeta> (Ge  (CN 0 c e)) = c"
 27.2402 -  "\<zeta> (Dvd i (CN 0 c e)) = c"
 27.2403 -  "\<zeta> (NDvd i (CN 0 c e))= c"
 27.2404 -  "\<zeta> p = 1"
 27.2405 -
 27.2406 -recdef \<beta> "measure size"
 27.2407 -  "\<beta> (And p q) = (\<beta> p @ \<beta> q)" 
 27.2408 -  "\<beta> (Or p q) = (\<beta> p @ \<beta> q)" 
 27.2409 -  "\<beta> (Eq  (CN 0 c e)) = [Sub (C -1) e]"
 27.2410 -  "\<beta> (NEq (CN 0 c e)) = [Neg e]"
 27.2411 -  "\<beta> (Lt  (CN 0 c e)) = []"
 27.2412 -  "\<beta> (Le  (CN 0 c e)) = []"
 27.2413 -  "\<beta> (Gt  (CN 0 c e)) = [Neg e]"
 27.2414 -  "\<beta> (Ge  (CN 0 c e)) = [Sub (C -1) e]"
 27.2415 -  "\<beta> p = []"
 27.2416 -
 27.2417 -recdef \<alpha> "measure size"
 27.2418 -  "\<alpha> (And p q) = (\<alpha> p @ \<alpha> q)" 
 27.2419 -  "\<alpha> (Or p q) = (\<alpha> p @ \<alpha> q)" 
 27.2420 -  "\<alpha> (Eq  (CN 0 c e)) = [Add (C -1) e]"
 27.2421 -  "\<alpha> (NEq (CN 0 c e)) = [e]"
 27.2422 -  "\<alpha> (Lt  (CN 0 c e)) = [e]"
 27.2423 -  "\<alpha> (Le  (CN 0 c e)) = [Add (C -1) e]"
 27.2424 -  "\<alpha> (Gt  (CN 0 c e)) = []"
 27.2425 -  "\<alpha> (Ge  (CN 0 c e)) = []"
 27.2426 -  "\<alpha> p = []"
 27.2427 -consts mirror :: "fm \<Rightarrow> fm"
 27.2428 -recdef mirror "measure size"
 27.2429 -  "mirror (And p q) = And (mirror p) (mirror q)" 
 27.2430 -  "mirror (Or p q) = Or (mirror p) (mirror q)" 
 27.2431 -  "mirror (Eq  (CN 0 c e)) = Eq (CN 0 c (Neg e))"
 27.2432 -  "mirror (NEq (CN 0 c e)) = NEq (CN 0 c (Neg e))"
 27.2433 -  "mirror (Lt  (CN 0 c e)) = Gt (CN 0 c (Neg e))"
 27.2434 -  "mirror (Le  (CN 0 c e)) = Ge (CN 0 c (Neg e))"
 27.2435 -  "mirror (Gt  (CN 0 c e)) = Lt (CN 0 c (Neg e))"
 27.2436 -  "mirror (Ge  (CN 0 c e)) = Le (CN 0 c (Neg e))"
 27.2437 -  "mirror (Dvd i (CN 0 c e)) = Dvd i (CN 0 c (Neg e))"
 27.2438 -  "mirror (NDvd i (CN 0 c e)) = NDvd i (CN 0 c (Neg e))"
 27.2439 -  "mirror p = p"
 27.2440 -
 27.2441 -lemma mirror\<alpha>\<beta>:
 27.2442 -  assumes lp: "iszlfm p (a#bs)"
 27.2443 -  shows "(Inum (real (i::int)#bs)) ` set (\<alpha> p) = (Inum (real i#bs)) ` set (\<beta> (mirror p))"
 27.2444 -using lp
 27.2445 -by (induct p rule: mirror.induct, auto)
 27.2446 -
 27.2447 -lemma mirror: 
 27.2448 -  assumes lp: "iszlfm p (a#bs)"
 27.2449 -  shows "Ifm (real (x::int)#bs) (mirror p) = Ifm (real (- x)#bs) p" 
 27.2450 -using lp
 27.2451 -proof(induct p rule: iszlfm.induct)
 27.2452 -  case (9 j c e)
 27.2453 -  have th: "(real j rdvd real c * real x - Inum (real x # bs) e) =
 27.2454 -       (real j rdvd - (real c * real x - Inum (real x # bs) e))"
 27.2455 -    by (simp only: rdvd_minus[symmetric])
 27.2456 -  from prems show  ?case
 27.2457 -    by (simp add: ring_simps th[simplified ring_simps]
 27.2458 -      numbound0_I[where bs="bs" and b'="real x" and b="- real x"])
 27.2459 -next
 27.2460 -    case (10 j c e)
 27.2461 -  have th: "(real j rdvd real c * real x - Inum (real x # bs) e) =
 27.2462 -       (real j rdvd - (real c * real x - Inum (real x # bs) e))"
 27.2463 -    by (simp only: rdvd_minus[symmetric])
 27.2464 -  from prems show  ?case
 27.2465 -    by (simp add: ring_simps th[simplified ring_simps]
 27.2466 -      numbound0_I[where bs="bs" and b'="real x" and b="- real x"])
 27.2467 -qed (auto simp add: numbound0_I[where bs="bs" and b="real x" and b'="- real x"] nth_pos2)
 27.2468 -
 27.2469 -lemma mirror_l: "iszlfm p (a#bs) \<Longrightarrow> iszlfm (mirror p) (a#bs)"
 27.2470 -by (induct p rule: mirror.induct, auto simp add: isint_neg)
 27.2471 -
 27.2472 -lemma mirror_d\<beta>: "iszlfm p (a#bs) \<and> d\<beta> p 1 
 27.2473 -  \<Longrightarrow> iszlfm (mirror p) (a#bs) \<and> d\<beta> (mirror p) 1"
 27.2474 -by (induct p rule: mirror.induct, auto simp add: isint_neg)
 27.2475 -
 27.2476 -lemma mirror_\<delta>: "iszlfm p (a#bs) \<Longrightarrow> \<delta> (mirror p) = \<delta> p"
 27.2477 -by (induct p rule: mirror.induct,auto)
 27.2478 -
 27.2479 -
 27.2480 -lemma mirror_ex: 
 27.2481 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 27.2482 -  shows "(\<exists> (x::int). Ifm (real x#bs) (mirror p)) = (\<exists> (x::int). Ifm (real x#bs) p)"
 27.2483 -  (is "(\<exists> x. ?I x ?mp) = (\<exists> x. ?I x p)")
 27.2484 -proof(auto)
 27.2485 -  fix x assume "?I x ?mp" hence "?I (- x) p" using mirror[OF lp] by blast
 27.2486 -  thus "\<exists> x. ?I x p" by blast
 27.2487 -next
 27.2488 -  fix x assume "?I x p" hence "?I (- x) ?mp" 
 27.2489 -    using mirror[OF lp, where x="- x", symmetric] by auto
 27.2490 -  thus "\<exists> x. ?I x ?mp" by blast
 27.2491 -qed
 27.2492 -
 27.2493 -lemma \<beta>_numbound0: assumes lp: "iszlfm p bs"
 27.2494 -  shows "\<forall> b\<in> set (\<beta> p). numbound0 b"
 27.2495 -  using lp by (induct p rule: \<beta>.induct,auto)
 27.2496 -
 27.2497 -lemma d\<beta>_mono: 
 27.2498 -  assumes linp: "iszlfm p (a #bs)"
 27.2499 -  and dr: "d\<beta> p l"
 27.2500 -  and d: "l dvd l'"
 27.2501 -  shows "d\<beta> p l'"
 27.2502 -using dr linp zdvd_trans[where n="l" and k="l'", simplified d]
 27.2503 -by (induct p rule: iszlfm.induct) simp_all
 27.2504 -
 27.2505 -lemma \<alpha>_l: assumes lp: "iszlfm p (a#bs)"
 27.2506 -  shows "\<forall> b\<in> set (\<alpha> p). numbound0 b \<and> isint b (a#bs)"
 27.2507 -using lp
 27.2508 -by(induct p rule: \<alpha>.induct, auto simp add: isint_add isint_c)
 27.2509 -
 27.2510 -lemma \<zeta>: 
 27.2511 -  assumes linp: "iszlfm p (a #bs)"
 27.2512 -  shows "\<zeta> p > 0 \<and> d\<beta> p (\<zeta> p)"
 27.2513 -using linp
 27.2514 -proof(induct p rule: iszlfm.induct)
 27.2515 -  case (1 p q)
 27.2516 -  from prems have dl1: "\<zeta> p dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 27.2517 -  from prems have dl2: "\<zeta> q dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 27.2518 -  from prems d\<beta>_mono[where p = "p" and l="\<zeta> p" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 27.2519 -    d\<beta>_mono[where p = "q" and l="\<zeta> q" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 27.2520 -    dl1 dl2 show ?case by (auto simp add: zlcm_pos)
 27.2521 -next
 27.2522 -  case (2 p q)
 27.2523 -  from prems have dl1: "\<zeta> p dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 27.2524 -  from prems have dl2: "\<zeta> q dvd zlcm (\<zeta> p) (\<zeta> q)" by simp
 27.2525 -  from prems d\<beta>_mono[where p = "p" and l="\<zeta> p" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 27.2526 -    d\<beta>_mono[where p = "q" and l="\<zeta> q" and l'="zlcm (\<zeta> p) (\<zeta> q)"] 
 27.2527 -    dl1 dl2 show ?case by (auto simp add: zlcm_pos)
 27.2528 -qed (auto simp add: zlcm_pos)
 27.2529 -
 27.2530 -lemma a\<beta>: assumes linp: "iszlfm p (a #bs)" and d: "d\<beta> p l" and lp: "l > 0"
 27.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)"
 27.2532 -using linp d
 27.2533 -proof (induct p rule: iszlfm.induct)
 27.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+
 27.2535 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2536 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2537 -    have "c div c\<le> l div c"
 27.2538 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2539 -    then have ldcp:"0 < l div c" 
 27.2540 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2542 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2543 -      by simp
 27.2544 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e < (0\<Colon>real)) =
 27.2545 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e < 0)"
 27.2546 -      by simp
 27.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)
 27.2548 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e < 0)"
 27.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
 27.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
 27.2551 -next
 27.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+
 27.2553 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2554 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2555 -    have "c div c\<le> l div c"
 27.2556 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2557 -    then have ldcp:"0 < l div c" 
 27.2558 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2560 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2561 -      by simp
 27.2562 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e \<le> (0\<Colon>real)) =
 27.2563 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \<le> 0)"
 27.2564 -      by simp
 27.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)
 27.2566 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e \<le> 0)"
 27.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
 27.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
 27.2569 -next
 27.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+
 27.2571 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2572 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2573 -    have "c div c\<le> l div c"
 27.2574 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2575 -    then have ldcp:"0 < l div c" 
 27.2576 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2578 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2579 -      by simp
 27.2580 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e > (0\<Colon>real)) =
 27.2581 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e > 0)"
 27.2582 -      by simp
 27.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)
 27.2584 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e > 0)"
 27.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
 27.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
 27.2587 -next
 27.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+
 27.2589 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2590 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2591 -    have "c div c\<le> l div c"
 27.2592 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2593 -    then have ldcp:"0 < l div c" 
 27.2594 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2596 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2597 -      by simp
 27.2598 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e \<ge> (0\<Colon>real)) =
 27.2599 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \<ge> 0)"
 27.2600 -      by simp
 27.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)
 27.2602 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e \<ge> 0)"
 27.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
 27.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
 27.2605 -next
 27.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+
 27.2607 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2608 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2609 -    have "c div c\<le> l div c"
 27.2610 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2611 -    then have ldcp:"0 < l div c" 
 27.2612 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2614 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2615 -      by simp
 27.2616 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e = (0\<Colon>real)) =
 27.2617 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e = 0)"
 27.2618 -      by simp
 27.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)
 27.2620 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e = 0)"
 27.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
 27.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
 27.2623 -next
 27.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+
 27.2625 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2626 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2627 -    have "c div c\<le> l div c"
 27.2628 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2629 -    then have ldcp:"0 < l div c" 
 27.2630 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2632 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2633 -      by simp
 27.2634 -    hence "(real l * real x + real (l div c) * Inum (real x # bs) e \<noteq> (0\<Colon>real)) =
 27.2635 -          (real (c * (l div c)) * real x + real (l div c) * Inum (real x # bs) e \<noteq> 0)"
 27.2636 -      by simp
 27.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)
 27.2638 -    also have "\<dots> = (real c * real x + Inum (real x # bs) e \<noteq> 0)"
 27.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
 27.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
 27.2641 -next
 27.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+
 27.2643 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2644 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2645 -    have "c div c\<le> l div c"
 27.2646 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2647 -    then have ldcp:"0 < l div c" 
 27.2648 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2650 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2651 -      by simp
 27.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
 27.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)
 27.2654 -    also fix k have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)"
 27.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
 27.2656 -  also have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp
 27.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 
 27.2658 -next
 27.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+
 27.2660 -    from lp cp have clel: "c\<le>l" by (simp add: zdvd_imp_le [OF d' lp])
 27.2661 -    from cp have cnz: "c \<noteq> 0" by simp
 27.2662 -    have "c div c\<le> l div c"
 27.2663 -      by (simp add: zdiv_mono1[OF clel cp])
 27.2664 -    then have ldcp:"0 < l div c" 
 27.2665 -      by (simp add: zdiv_self[OF cnz])
 27.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
 27.2667 -    hence cl:"c * (l div c) =l" using zmod_zdiv_equality[where a="l" and b="c", symmetric] 
 27.2668 -      by simp
 27.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
 27.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)
 27.2671 -    also fix k have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e - real j * real k = 0)"
 27.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
 27.2673 -  also have "\<dots> = (\<exists> (k::int). real c * real x + Inum (real x # bs) e = real j * real k)" by simp
 27.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
 27.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)
 27.2676 -
 27.2677 -lemma a\<beta>_ex: assumes linp: "iszlfm p (a#bs)" and d: "d\<beta> p l" and lp: "l>0"
 27.2678 -  shows "(\<exists> x. l dvd x \<and> Ifm (real x #bs) (a\<beta> p l)) = (\<exists> (x::int). Ifm (real x#bs) p)"
 27.2679 -  (is "(\<exists> x. l dvd x \<and> ?P x) = (\<exists> x. ?P' x)")
 27.2680 -proof-
 27.2681 -  have "(\<exists> x. l dvd x \<and> ?P x) = (\<exists> (x::int). ?P (l*x))"
 27.2682 -    using unity_coeff_ex[where l="l" and P="?P", simplified] by simp
 27.2683 -  also have "\<dots> = (\<exists> (x::int). ?P' x)" using a\<beta>[OF linp d lp] by simp
 27.2684 -  finally show ?thesis  . 
 27.2685 -qed
 27.2686 -
 27.2687 -lemma \<beta>:
 27.2688 -  assumes lp: "iszlfm p (a#bs)"
 27.2689 -  and u: "d\<beta> p 1"
 27.2690 -  and d: "d\<delta> p d"
 27.2691 -  and dp: "d > 0"
 27.2692 -  and nob: "\<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> (Inum (a#bs)) ` set(\<beta> p). real x = b + real j)"
 27.2693 -  and p: "Ifm (real x#bs) p" (is "?P x")
 27.2694 -  shows "?P (x - d)"
 27.2695 -using lp u d dp nob p
 27.2696 -proof(induct p rule: iszlfm.induct)
 27.2697 -  case (5 c e) hence c1: "c=1" and  bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 27.2698 -    with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems
 27.2699 -    show ?case by (simp del: real_of_int_minus)
 27.2700 -next
 27.2701 -  case (6 c e)  hence c1: "c=1" and  bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 27.2702 -    with dp p c1 numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] prems
 27.2703 -    show ?case by (simp del: real_of_int_minus)
 27.2704 -next
 27.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+
 27.2706 -    let ?e = "Inum (real x # bs) e"
 27.2707 -    from ie1 have ie: "real (floor ?e) = ?e" using isint_iff[where n="e" and bs="a#bs"]
 27.2708 -      numbound0_I[OF bn,where b="a" and b'="real x" and bs="bs"]
 27.2709 -      by (simp add: isint_iff)
 27.2710 -    {assume "real (x-d) +?e > 0" hence ?case using c1 
 27.2711 -      numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"]
 27.2712 -	by (simp del: real_of_int_minus)}
 27.2713 -    moreover
 27.2714 -    {assume H: "\<not> real (x-d) + ?e > 0" 
 27.2715 -      let ?v="Neg e"
 27.2716 -      have vb: "?v \<in> set (\<beta> (Gt (CN 0 c e)))" by simp
 27.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"]] 
 27.2718 -      have nob: "\<not> (\<exists> j\<in> {1 ..d}. real x =  - ?e + real j)" by auto 
 27.2719 -      from H p have "real x + ?e > 0 \<and> real x + ?e \<le> real d" by (simp add: c1)
 27.2720 -      hence "real (x + floor ?e) > real (0::int) \<and> real (x + floor ?e) \<le> real d"
 27.2721 -	using ie by simp
 27.2722 -      hence "x + floor ?e \<ge> 1 \<and> x + floor ?e \<le> d"  by simp
 27.2723 -      hence "\<exists> (j::int) \<in> {1 .. d}. j = x + floor ?e" by simp
 27.2724 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x = real (- floor ?e + j)" 
 27.2725 -	by (simp only: real_of_int_inject) (simp add: ring_simps)
 27.2726 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x = - ?e + real j" 
 27.2727 -	by (simp add: ie[simplified isint_iff])
 27.2728 -      with nob have ?case by auto}
 27.2729 -    ultimately show ?case by blast
 27.2730 -next
 27.2731 -  case (8 c e) hence p: "Ifm (real x #bs) (Ge (CN 0 c e))" and c1: "c=1" and bn:"numbound0 e" 
 27.2732 -    and ie1:"isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+
 27.2733 -    let ?e = "Inum (real x # bs) e"
 27.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"]
 27.2735 -      by (simp add: isint_iff)
 27.2736 -    {assume "real (x-d) +?e \<ge> 0" hence ?case using  c1 
 27.2737 -      numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"]
 27.2738 -	by (simp del: real_of_int_minus)}
 27.2739 -    moreover
 27.2740 -    {assume H: "\<not> real (x-d) + ?e \<ge> 0" 
 27.2741 -      let ?v="Sub (C -1) e"
 27.2742 -      have vb: "?v \<in> set (\<beta> (Ge (CN 0 c e)))" by simp
 27.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"]] 
 27.2744 -      have nob: "\<not> (\<exists> j\<in> {1 ..d}. real x =  - ?e - 1 + real j)" by auto 
 27.2745 -      from H p have "real x + ?e \<ge> 0 \<and> real x + ?e < real d" by (simp add: c1)
 27.2746 -      hence "real (x + floor ?e) \<ge> real (0::int) \<and> real (x + floor ?e) < real d"
 27.2747 -	using ie by simp
 27.2748 -      hence "x + floor ?e +1 \<ge> 1 \<and> x + floor ?e + 1 \<le> d"  by simp
 27.2749 -      hence "\<exists> (j::int) \<in> {1 .. d}. j = x + floor ?e + 1" by simp
 27.2750 -      hence "\<exists> (j::int) \<in> {1 .. d}. x= - floor ?e - 1 + j" by (simp add: ring_simps)
 27.2751 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x= real (- floor ?e - 1 + j)" 
 27.2752 -	by (simp only: real_of_int_inject)
 27.2753 -      hence "\<exists> (j::int) \<in> {1 .. d}. real x= - ?e - 1 + real j" 
 27.2754 -	by (simp add: ie[simplified isint_iff])
 27.2755 -      with nob have ?case by simp }
 27.2756 -    ultimately show ?case by blast
 27.2757 -next
 27.2758 -  case (3 c e) hence p: "Ifm (real x #bs) (Eq (CN 0 c e))" (is "?p x") and c1: "c=1" 
 27.2759 -    and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+
 27.2760 -    let ?e = "Inum (real x # bs) e"
 27.2761 -    let ?v="(Sub (C -1) e)"
 27.2762 -    have vb: "?v \<in> set (\<beta> (Eq (CN 0 c e)))" by simp
 27.2763 -    from p have "real x= - ?e" by (simp add: c1) with prems(11) show ?case using dp
 27.2764 -      by simp (erule ballE[where x="1"],
 27.2765 -	simp_all add:ring_simps numbound0_I[OF bn,where b="real x"and b'="a"and bs="bs"])
 27.2766 -next
 27.2767 -  case (4 c e)hence p: "Ifm (real x #bs) (NEq (CN 0 c e))" (is "?p x") and c1: "c=1" 
 27.2768 -    and bn:"numbound0 e" and ie1: "isint e (a #bs)" using dvd1_eq1[where x="c"] by simp+
 27.2769 -    let ?e = "Inum (real x # bs) e"
 27.2770 -    let ?v="Neg e"
 27.2771 -    have vb: "?v \<in> set (\<beta> (NEq (CN 0 c e)))" by simp
 27.2772 -    {assume "real x - real d + Inum ((real (x -d)) # bs) e \<noteq> 0" 
 27.2773 -      hence ?case by (simp add: c1)}
 27.2774 -    moreover
 27.2775 -    {assume H: "real x - real d + Inum ((real (x -d)) # bs) e = 0"
 27.2776 -      hence "real x = - Inum ((real (x -d)) # bs) e + real d" by simp
 27.2777 -      hence "real x = - Inum (a # bs) e + real d"
 27.2778 -	by (simp add: numbound0_I[OF bn,where b="real x - real d"and b'="a"and bs="bs"])
 27.2779 -       with prems(11) have ?case using dp by simp}
 27.2780 -  ultimately show ?case by blast
 27.2781 -next 
 27.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" 
 27.2783 -    and bn:"numbound0 e" using dvd1_eq1[where x="c"] by simp+
 27.2784 -    let ?e = "Inum (real x # bs) e"
 27.2785 -    from prems have "isint e (a #bs)"  by simp 
 27.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"]
 27.2787 -      by (simp add: isint_iff)
 27.2788 -    from prems have id: "j dvd d" by simp
 27.2789 -    from c1 ie[symmetric] have "?p x = (real j rdvd real (x+ floor ?e))" by simp
 27.2790 -    also have "\<dots> = (j dvd x + floor ?e)" 
 27.2791 -      using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp
 27.2792 -    also have "\<dots> = (j dvd x - d + floor ?e)" 
 27.2793 -      using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp
 27.2794 -    also have "\<dots> = (real j rdvd real (x - d + floor ?e))" 
 27.2795 -      using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified]
 27.2796 -      ie by simp
 27.2797 -    also have "\<dots> = (real j rdvd real x - real d + ?e)" 
 27.2798 -      using ie by simp
 27.2799 -    finally show ?case 
 27.2800 -      using numbound0_I[OF bn,where b="real (x-d)" and b'="real x" and bs="bs"] c1 p by simp
 27.2801 -next
 27.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+
 27.2803 -    let ?e = "Inum (real x # bs) e"
 27.2804 -    from prems have "isint e (a#bs)"  by simp 
 27.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"]
 27.2806 -      by (simp add: isint_iff)
 27.2807 -    from prems have id: "j dvd d" by simp
 27.2808 -    from c1 ie[symmetric] have "?p x = (\<not> real j rdvd real (x+ floor ?e))" by simp
 27.2809 -    also have "\<dots> = (\<not> j dvd x + floor ?e)" 
 27.2810 -      using int_rdvd_real[where i="j" and x="real (x+ floor ?e)"] by simp
 27.2811 -    also have "\<dots> = (\<not> j dvd x - d + floor ?e)" 
 27.2812 -      using dvd_period[OF id, where x="x" and c="-1" and t="floor ?e"] by simp
 27.2813 -    also have "\<dots> = (\<not> real j rdvd real (x - d + floor ?e))" 
 27.2814 -      using int_rdvd_real[where i="j" and x="real (x-d + floor ?e)",symmetric, simplified]
 27.2815 -      ie by simp
 27.2816 -    also have "\<dots> = (\<not> real j rdvd real x - real d + ?e)" 
 27.2817 -      using ie by simp
 27.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
 27.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)
 27.2820 -
 27.2821 -lemma \<beta>':   
 27.2822 -  assumes lp: "iszlfm p (a #bs)"
 27.2823 -  and u: "d\<beta> p 1"
 27.2824 -  and d: "d\<delta> p d"
 27.2825 -  and dp: "d > 0"
 27.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)")
 27.2827 -proof(clarify)
 27.2828 -  fix x 
 27.2829 -  assume nb:"?b" and px: "?P x" 
 27.2830 -  hence nb2: "\<not>(\<exists>(j::int) \<in> {1 .. d}. \<exists> b\<in> (Inum (a#bs)) ` set(\<beta> p). real x = b + real j)"
 27.2831 -    by auto
 27.2832 -  from  \<beta>[OF lp u d dp nb2 px] show "?P (x -d )" .
 27.2833 -qed
 27.2834 -
 27.2835 -lemma \<beta>_int: assumes lp: "iszlfm p bs"
 27.2836 -  shows "\<forall> b\<in> set (\<beta> p). isint b bs"
 27.2837 -using lp by (induct p rule: iszlfm.induct) (auto simp add: isint_neg isint_sub)
 27.2838 -
 27.2839 -lemma cpmi_eq: "0 < D \<Longrightarrow> (EX z::int. ALL x. x < z --> (P x = P1 x))
 27.2840 -==> ALL x.~(EX (j::int) : {1..D}. EX (b::int) : B. P(b+j)) --> P (x) --> P (x - D) 
 27.2841 -==> (ALL (x::int). ALL (k::int). ((P1 x)= (P1 (x-k*D))))
 27.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)))"
 27.2843 -apply(rule iffI)
 27.2844 -prefer 2
 27.2845 -apply(drule minusinfinity)
 27.2846 -apply assumption+
 27.2847 -apply(fastsimp)
 27.2848 -apply clarsimp
 27.2849 -apply(subgoal_tac "!!k. 0<=k \<Longrightarrow> !x. P x \<longrightarrow> P (x - k*D)")
 27.2850 -apply(frule_tac x = x and z=z in decr_lemma)
 27.2851 -apply(subgoal_tac "P1(x - (\<bar>x - z\<bar> + 1) * D)")
 27.2852 -prefer 2
 27.2853 -apply(subgoal_tac "0 <= (\<bar>x - z\<bar> + 1)")
 27.2854 -prefer 2 apply arith
 27.2855 - apply fastsimp
 27.2856 -apply(drule (1)  periodic_finite_ex)
 27.2857 -apply blast
 27.2858 -apply(blast dest:decr_mult_lemma)
 27.2859 -done
 27.2860 -
 27.2861 -
 27.2862 -theorem cp_thm:
 27.2863 -  assumes lp: "iszlfm p (a #bs)"
 27.2864 -  and u: "d\<beta> p 1"
 27.2865 -  and d: "d\<delta> p d"
 27.2866 -  and dp: "d > 0"
 27.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))"
 27.2868 -  (is "(\<exists> (x::int). ?P (real x)) = (\<exists> j\<in> ?D. ?M j \<or> (\<exists> b\<in> ?B. ?P (?I b + real j)))")
 27.2869 -proof-
 27.2870 -  from minusinf_inf[OF lp] 
 27.2871 -  have th: "\<exists>(z::int). \<forall>x<z. ?P (real x) = ?M x" by blast
 27.2872 -  let ?B' = "{floor (?I b) | b. b\<in> ?B}"
 27.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
 27.2874 -  from B[rule_format] 
 27.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))" 
 27.2876 -    by simp
 27.2877 -  also have "\<dots> = (\<exists>j\<in>?D. \<exists>b\<in> ?B. ?P (real (floor (?I b) + j)))" by simp
 27.2878 -  also have"\<dots> = (\<exists> j \<in> ?D. \<exists> b \<in> ?B'. ?P (real (b + j)))"  by blast
 27.2879 -  finally have BB': 
 27.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)))" 
 27.2881 -    by blast 
 27.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
 27.2883 -  from minusinf_repeats[OF d lp]
 27.2884 -  have th3: "\<forall> x k. ?M x = ?M (x-k*d)" by simp
 27.2885 -  from cpmi_eq[OF dp th th2 th3] BB' show ?thesis by blast
 27.2886 -qed
 27.2887 -
 27.2888 -    (* Reddy and Loveland *)
 27.2889 -
 27.2890 -
 27.2891 -consts 
 27.2892 -  \<rho> :: "fm \<Rightarrow> (num \<times> int) list" (* Compute the Reddy and Loveland Bset*)
 27.2893 -  \<sigma>\<rho>:: "fm \<Rightarrow> num \<times> int \<Rightarrow> fm" (* Performs the modified substitution of Reddy and Loveland*)
 27.2894 -  \<alpha>\<rho> :: "fm \<Rightarrow> (num\<times>int) list"
 27.2895 -  a\<rho> :: "fm \<Rightarrow> int \<Rightarrow> fm"
 27.2896 -recdef \<rho> "measure size"
 27.2897 -  "\<rho> (And p q) = (\<rho> p @ \<rho> q)" 
 27.2898 -  "\<rho> (Or p q) = (\<rho> p @ \<rho> q)" 
 27.2899 -  "\<rho> (Eq  (CN 0 c e)) = [(Sub (C -1) e,c)]"
 27.2900 -  "\<rho> (NEq (CN 0 c e)) = [(Neg e,c)]"
 27.2901 -  "\<rho> (Lt  (CN 0 c e)) = []"
 27.2902 -  "\<rho> (Le  (CN 0 c e)) = []"
 27.2903 -  "\<rho> (Gt  (CN 0 c e)) = [(Neg e, c)]"
 27.2904 -  "\<rho> (Ge  (CN 0 c e)) = [(Sub (C (-1)) e, c)]"
 27.2905 -  "\<rho> p = []"
 27.2906 -
 27.2907 -recdef \<sigma>\<rho> "measure size"
 27.2908 -  "\<sigma>\<rho> (And p q) = (\<lambda> (t,k). And (\<sigma>\<rho> p (t,k)) (\<sigma>\<rho> q (t,k)))" 
 27.2909 -  "\<sigma>\<rho> (Or p q) = (\<lambda> (t,k). Or (\<sigma>\<rho> p (t,k)) (\<sigma>\<rho> q (t,k)))" 
 27.2910 -  "\<sigma>\<rho> (Eq  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Eq (Add (Mul (c div k) t) e)) 
 27.2911 -                                            else (Eq (Add (Mul c t) (Mul k e))))"
 27.2912 -  "\<sigma>\<rho> (NEq (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (NEq (Add (Mul (c div k) t) e)) 
 27.2913 -                                            else (NEq (Add (Mul c t) (Mul k e))))"
 27.2914 -  "\<sigma>\<rho> (Lt  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Lt (Add (Mul (c div k) t) e)) 
 27.2915 -                                            else (Lt (Add (Mul c t) (Mul k e))))"
 27.2916 -  "\<sigma>\<rho> (Le  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Le (Add (Mul (c div k) t) e)) 
 27.2917 -                                            else (Le (Add (Mul c t) (Mul k e))))"
 27.2918 -  "\<sigma>\<rho> (Gt  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Gt (Add (Mul (c div k) t) e)) 
 27.2919 -                                            else (Gt (Add (Mul c t) (Mul k e))))"
 27.2920 -  "\<sigma>\<rho> (Ge  (CN 0 c e)) = (\<lambda> (t,k). if k dvd c then (Ge (Add (Mul (c div k) t) e)) 
 27.2921 -                                            else (Ge (Add (Mul c t) (Mul k e))))"
 27.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)) 
 27.2923 -                                            else (Dvd (i*k) (Add (Mul c t) (Mul k e))))"
 27.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)) 
 27.2925 -                                            else (NDvd (i*k) (Add (Mul c t) (Mul k e))))"
 27.2926 -  "\<sigma>\<rho> p = (\<lambda> (t,k). p)"
 27.2927 -
 27.2928 -recdef \<alpha>\<rho> "measure size"
 27.2929 -  "\<alpha>\<rho> (And p q) = (\<alpha>\<rho> p @ \<alpha>\<rho> q)" 
 27.2930 -  "\<alpha>\<rho> (Or p q) = (\<alpha>\<rho> p @ \<alpha>\<rho> q)" 
 27.2931 -  "\<alpha>\<rho> (Eq  (CN 0 c e)) = [(Add (C -1) e,c)]"
 27.2932 -  "\<alpha>\<rho> (NEq (CN 0 c e)) = [(e,c)]"
 27.2933 -  "\<alpha>\<rho> (Lt  (CN 0 c e)) = [(e,c)]"
 27.2934 -  "\<alpha>\<rho> (Le  (CN 0 c e)) = [(Add (C -1) e,c)]"
 27.2935 -  "\<alpha>\<rho> p = []"
 27.2936 -
 27.2937 -    (* Simulates normal substituion by modifying the formula see correctness theorem *)
 27.2938 -
 27.2939 -recdef a\<rho> "measure size"
 27.2940 -  "a\<rho> (And p q) = (\<lambda> k. And (a\<rho> p k) (a\<rho> q k))" 
 27.2941 -  "a\<rho> (Or p q) = (\<lambda> k. Or (a\<rho> p k) (a\<rho> q k))" 
 27.2942 -  "a\<rho> (Eq (CN 0 c e)) = (\<lambda> k. if k dvd c then (Eq (CN 0 (c div k) e)) 
 27.2943 -                                           else (Eq (CN 0 c (Mul k e))))"
 27.2944 -  "a\<rho> (NEq (CN 0 c e)) = (\<lambda> k. if k dvd c then (NEq (CN 0 (c div k) e)) 
 27.2945 -                                           else (NEq (CN 0 c (Mul k e))))"
 27.2946 -  "a\<rho> (Lt (CN 0 c e)) = (\<lambda> k. if k dvd c then (Lt (CN 0 (c div k) e)) 
 27.2947 -                                           else (Lt (CN 0 c (Mul k e))))"
 27.2948 -  "a\<rho> (Le (CN 0 c e)) = (\<lambda> k. if k dvd c then (Le (CN 0 (c div k) e)) 
 27.2949 -                                           else (Le (CN 0 c (Mul k e))))"
 27.2950 -  "a\<rho> (Gt (CN 0 c e)) = (\<lambda> k. if k dvd c then (Gt (CN 0 (c div k) e)) 
 27.2951 -                                           else (Gt (CN 0 c (Mul k e))))"
 27.2952 -  "a\<rho> (Ge (CN 0 c e)) = (\<lambda> k. if k dvd c then (Ge (CN 0 (c div k) e)) 
 27.2953 -                                            else (Ge (CN 0 c (Mul k e))))"
 27.2954 -  "a\<rho> (Dvd i (CN 0 c e)) = (\<lambda> k. if k dvd c then (Dvd i (CN 0 (c div k) e)) 
 27.2955 -                                            else (Dvd (i*k) (CN 0 c (Mul k e))))"
 27.2956 -  "a\<rho> (NDvd i (CN 0 c e)) = (\<lambda> k. if k dvd c then (NDvd i (CN 0 (c div k) e)) 
 27.2957 -                                            else (NDvd (i*k) (CN 0 c (Mul k e))))"
 27.2958 -  "a\<rho> p = (\<lambda> k. p)"
 27.2959 -
 27.2960 -constdefs \<sigma> :: "fm \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm"
 27.2961 -  "\<sigma> p k t \<equiv> And (Dvd k t) (\<sigma>\<rho> p (t,k))"
 27.2962 -
 27.2963 -lemma \<sigma>\<rho>:
 27.2964 -  assumes linp: "iszlfm p (real (x::int)#bs)"
 27.2965 -  and kpos: "real k > 0"
 27.2966 -  and tnb: "numbound0 t"
 27.2967 -  and tint: "isint t (real x#bs)"
 27.2968 -  and kdt: "k dvd floor (Inum (b'#bs) t)"
 27.2969 -  shows "Ifm (real x#bs) (\<sigma>\<rho> p (t,k)) = 
 27.2970 -  (Ifm ((real ((floor (Inum (b'#bs) t)) div k))#bs) p)" 
 27.2971 -  (is "?I (real x) (?s p) = (?I (real ((floor (?N b' t)) div k)) p)" is "_ = (?I ?tk p)")
 27.2972 -using linp kpos tnb
 27.2973 -proof(induct p rule: \<sigma>\<rho>.induct)
 27.2974 -  case (3 c e) 
 27.2975 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.2976 -    {assume kdc: "k dvd c" 
 27.2977 -      from kpos have knz: "k\<noteq>0" by simp
 27.2978 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.2979 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.2980 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.2981 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.2982 -    moreover 
 27.2983 -    {assume "\<not> k dvd c"
 27.2984 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.2985 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.2987 -	using real_of_int_div[OF knz kdt]
 27.2988 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.2989 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.2991 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.2992 -	by (simp add: ti)
 27.2993 -      finally have ?case . }
 27.2994 -    ultimately show ?case by blast 
 27.2995 -next
 27.2996 -  case (4 c e)  
 27.2997 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.2998 -    {assume kdc: "k dvd c" 
 27.2999 -      from kpos have knz: "k\<noteq>0" by simp
 27.3000 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3001 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3002 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3003 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3004 -    moreover 
 27.3005 -    {assume "\<not> k dvd c"
 27.3006 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3007 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.3009 -	using real_of_int_div[OF knz kdt]
 27.3010 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3011 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3013 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3014 -	by (simp add: ti)
 27.3015 -      finally have ?case . }
 27.3016 -    ultimately show ?case by blast 
 27.3017 -next
 27.3018 -  case (5 c e) 
 27.3019 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3020 -    {assume kdc: "k dvd c" 
 27.3021 -      from kpos have knz: "k\<noteq>0" by simp
 27.3022 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3023 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3024 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3025 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3026 -    moreover 
 27.3027 -    {assume "\<not> k dvd c"
 27.3028 -      from kpos have knz: "k\<noteq>0" by simp
 27.3029 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.3031 -	using real_of_int_div[OF knz kdt]
 27.3032 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3033 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3035 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3036 -	by (simp add: ti)
 27.3037 -      finally have ?case . }
 27.3038 -    ultimately show ?case by blast 
 27.3039 -next
 27.3040 -  case (6 c e)  
 27.3041 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3042 -    {assume kdc: "k dvd c" 
 27.3043 -      from kpos have knz: "k\<noteq>0" by simp
 27.3044 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3045 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3046 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3047 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3048 -    moreover 
 27.3049 -    {assume "\<not> k dvd c"
 27.3050 -      from kpos have knz: "k\<noteq>0" by simp
 27.3051 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.3053 -	using real_of_int_div[OF knz kdt]
 27.3054 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3055 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3057 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3058 -	by (simp add: ti)
 27.3059 -      finally have ?case . }
 27.3060 -    ultimately show ?case by blast 
 27.3061 -next
 27.3062 -  case (7 c e) 
 27.3063 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3064 -    {assume kdc: "k dvd c" 
 27.3065 -      from kpos have knz: "k\<noteq>0" by simp
 27.3066 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3067 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3068 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3069 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3070 -    moreover 
 27.3071 -    {assume "\<not> k dvd c"
 27.3072 -      from kpos have knz: "k\<noteq>0" by simp
 27.3073 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.3075 -	using real_of_int_div[OF knz kdt]
 27.3076 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3077 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3079 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3080 -	by (simp add: ti)
 27.3081 -      finally have ?case . }
 27.3082 -    ultimately show ?case by blast 
 27.3083 -next
 27.3084 -  case (8 c e)  
 27.3085 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3086 -    {assume kdc: "k dvd c" 
 27.3087 -      from kpos have knz: "k\<noteq>0" by simp
 27.3088 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3089 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3090 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3091 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3092 -    moreover 
 27.3093 -    {assume "\<not> k dvd c"
 27.3094 -      from kpos have knz: "k\<noteq>0" by simp
 27.3095 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.3097 -	using real_of_int_div[OF knz kdt]
 27.3098 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3099 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3101 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3102 -	by (simp add: ti)
 27.3103 -      finally have ?case . }
 27.3104 -    ultimately show ?case by blast 
 27.3105 -next
 27.3106 -  case (9 i c e)   from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3107 -    {assume kdc: "k dvd c" 
 27.3108 -      from kpos have knz: "k\<noteq>0" by simp
 27.3109 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3110 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3111 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3112 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3113 -    moreover 
 27.3114 -    {assume "\<not> k dvd c"
 27.3115 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3116 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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)"
 27.3118 -	using real_of_int_div[OF knz kdt]
 27.3119 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3120 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3122 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3123 -	by (simp add: ti)
 27.3124 -      finally have ?case . }
 27.3125 -    ultimately show ?case by blast 
 27.3126 -next
 27.3127 -  case (10 i c e)    from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3128 -    {assume kdc: "k dvd c" 
 27.3129 -      from kpos have knz: "k\<noteq>0" by simp
 27.3130 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.3131 -      from prems have  ?case using real_of_int_div[OF knz kdc] real_of_int_div[OF knz kdt]
 27.3132 -	numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3133 -      numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti) } 
 27.3134 -    moreover 
 27.3135 -    {assume "\<not> k dvd c"
 27.3136 -      from kpos have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3137 -      from tint have ti: "real (floor (?N (real x) t)) = ?N (real x) t" using isint_def by simp
 27.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))"
 27.3139 -	using real_of_int_div[OF knz kdt]
 27.3140 -	  numbound0_I[OF tnb, where bs="bs" and b="b'" and b'="real x"]
 27.3141 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"] by (simp add: ti ring_simps)
 27.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"]
 27.3143 -	  numbound0_I[OF nb, where bs="bs" and b="?tk" and b'="real x"]
 27.3144 -	by (simp add: ti)
 27.3145 -      finally have ?case . }
 27.3146 -    ultimately show ?case by blast 
 27.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"])
 27.3148 -
 27.3149 -
 27.3150 -lemma a\<rho>: 
 27.3151 -  assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "real k > 0" 
 27.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")
 27.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"]
 27.3154 -proof(induct p rule: a\<rho>.induct)
 27.3155 -  case (3 c e)  
 27.3156 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3157 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3158 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3159 -    moreover 
 27.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)}
 27.3161 -    ultimately show ?case by blast 
 27.3162 -next
 27.3163 -  case (4 c e)   
 27.3164 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3165 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3166 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3167 -    moreover 
 27.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)}
 27.3169 -    ultimately show ?case by blast 
 27.3170 -next
 27.3171 -  case (5 c e)   
 27.3172 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3173 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3174 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3175 -    moreover 
 27.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)}
 27.3177 -    ultimately show ?case by blast 
 27.3178 -next
 27.3179 -  case (6 c e)    
 27.3180 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3181 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3182 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3183 -    moreover 
 27.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)}
 27.3185 -    ultimately show ?case by blast 
 27.3186 -next
 27.3187 -  case (7 c e)    
 27.3188 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3189 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3190 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3191 -    moreover 
 27.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)}
 27.3193 -    ultimately show ?case by blast 
 27.3194 -next
 27.3195 -  case (8 c e)    
 27.3196 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3197 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3198 -    {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3199 -    moreover 
 27.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)}
 27.3201 -    ultimately show ?case by blast 
 27.3202 -next
 27.3203 -  case (9 i c e)
 27.3204 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3205 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3206 -  {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3207 -  moreover 
 27.3208 -  {assume "\<not> k dvd c"
 27.3209 -    hence "Ifm (real (x*k)#bs) (a\<rho> (Dvd i (CN 0 c e)) k) = 
 27.3210 -      (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k)" 
 27.3211 -      using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] 
 27.3212 -      by (simp add: ring_simps)
 27.3213 -    also have "\<dots> = (Ifm (real x#bs) (Dvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"])
 27.3214 -    finally have ?case . }
 27.3215 -  ultimately show ?case by blast 
 27.3216 -next
 27.3217 -  case (10 i c e) 
 27.3218 -  from prems have cp: "c > 0" and nb: "numbound0 e" by auto
 27.3219 -  from kp have knz: "k\<noteq>0" by simp hence knz': "real k \<noteq> 0" by simp
 27.3220 -  {assume kdc: "k dvd c" from prems have  ?case using real_of_int_div[OF knz kdc] by simp } 
 27.3221 -  moreover 
 27.3222 -  {assume "\<not> k dvd c"
 27.3223 -    hence "Ifm (real (x*k)#bs) (a\<rho> (NDvd i (CN 0 c e)) k) = 
 27.3224 -      (\<not> (real i * real k rdvd (real c * real x + Inum (real x#bs) e) * real k))" 
 27.3225 -      using numbound0_I[OF nb, where bs="bs" and b="real (x*k)" and b'="real x"] 
 27.3226 -      by (simp add: ring_simps)
 27.3227 -    also have "\<dots> = (Ifm (real x#bs) (NDvd i (CN 0 c e)))" by (simp add: rdvd_mult[OF knz, where n="i"])
 27.3228 -    finally have ?case . }
 27.3229 -  ultimately show ?case by blast 
 27.3230 -qed (simp_all add: nth_pos2)
 27.3231 -
 27.3232 -lemma a\<rho>_ex: 
 27.3233 -  assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0"
 27.3234 -  shows "(\<exists> (x::int). real k rdvd real x \<and> Ifm (real x#bs) (a\<rho> p k)) = 
 27.3235 -  (\<exists> (x::int). Ifm (real x#bs) p)" (is "(\<exists> x. ?D x \<and> ?P' x) = (\<exists> x. ?P x)")
 27.3236 -proof-
 27.3237 -  have "(\<exists> x. ?D x \<and> ?P' x) = (\<exists> x. k dvd x \<and> ?P' x)" using int_rdvd_iff by simp
 27.3238 -  also have "\<dots> = (\<exists>x. ?P' (x*k))" using unity_coeff_ex[where P="?P'" and l="k", simplified]
 27.3239 -    by (simp add: ring_simps)
 27.3240 -  also have "\<dots> = (\<exists> x. ?P x)" using a\<rho> iszlfm_gen[OF lp] kp by auto
 27.3241 -  finally show ?thesis .
 27.3242 -qed
 27.3243 -
 27.3244 -lemma \<sigma>\<rho>': assumes lp: "iszlfm p (real (x::int)#bs)" and kp: "k > 0" and nb: "numbound0 t"
 27.3245 -  shows "Ifm (real x#bs) (\<sigma>\<rho> p (t,k)) = Ifm ((Inum (real x#bs) t)#bs) (a\<rho> p k)"
 27.3246 -using lp 
 27.3247 -by(induct p rule: \<sigma>\<rho>.induct, simp_all add: 
 27.3248 -  numbound0_I[OF nb, where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] 
 27.3249 -  numbound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] 
 27.3250 -  bound0_I[where bs="bs" and b="Inum (real x#bs) t" and b'="real x"] nth_pos2 cong: imp_cong)
 27.3251 -
 27.3252 -lemma \<sigma>\<rho>_nb: assumes lp:"iszlfm p (a#bs)" and nb: "numbound0 t"
 27.3253 -  shows "bound0 (\<sigma>\<rho> p (t,k))"
 27.3254 -  using lp
 27.3255 -  by (induct p rule: iszlfm.induct, auto simp add: nb)
 27.3256 -
 27.3257 -lemma \<rho>_l:
 27.3258 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 27.3259 -  shows "\<forall> (b,k) \<in> set (\<rho> p). k >0 \<and> numbound0 b \<and> isint b (real i#bs)"
 27.3260 -using lp by (induct p rule: \<rho>.induct, auto simp add: isint_sub isint_neg)
 27.3261 -
 27.3262 -lemma \<alpha>\<rho>_l:
 27.3263 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 27.3264 -  shows "\<forall> (b,k) \<in> set (\<alpha>\<rho> p). k >0 \<and> numbound0 b \<and> isint b (real i#bs)"
 27.3265 -using lp isint_add [OF isint_c[where j="- 1"],where bs="real i#bs"]
 27.3266 - by (induct p rule: \<alpha>\<rho>.induct, auto)
 27.3267 -
 27.3268 -lemma zminusinf_\<rho>:
 27.3269 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 27.3270 -  and nmi: "\<not> (Ifm (real i#bs) (minusinf p))" (is "\<not> (Ifm (real i#bs) (?M p))")
 27.3271 -  and ex: "Ifm (real i#bs) p" (is "?I i p")
 27.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")
 27.3273 -  using lp nmi ex
 27.3274 -by (induct p rule: minusinf.induct, auto)
 27.3275 -
 27.3276 -
 27.3277 -lemma \<sigma>_And: "Ifm bs (\<sigma> (And p q) k t)  = Ifm bs (And (\<sigma> p k t) (\<sigma> q k t))"
 27.3278 -using \<sigma>_def by auto
 27.3279 -lemma \<sigma>_Or: "Ifm bs (\<sigma> (Or p q) k t)  = Ifm bs (Or (\<sigma> p k t) (\<sigma> q k t))"
 27.3280 -using \<sigma>_def by auto
 27.3281 -
 27.3282 -lemma \<rho>: assumes lp: "iszlfm p (real (i::int) #bs)"
 27.3283 -  and pi: "Ifm (real i#bs) p"
 27.3284 -  and d: "d\<delta> p d"
 27.3285 -  and dp: "d > 0"
 27.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"
 27.3287 -  (is "\<forall>(e,c) \<in> set (\<rho> p). \<forall> j\<in> {1 .. c*d}. _ \<noteq> ?N i e + _")
 27.3288 -  shows "Ifm (real(i - d)#bs) p"
 27.3289 -  using lp pi d nob
 27.3290 -proof(induct p rule: iszlfm.induct)
 27.3291 -  case (3 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 27.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"
 27.3293 -    by simp+
 27.3294 -  from mult_strict_left_mono[OF dp cp]  have one:"1 \<in> {1 .. c*d}" by auto
 27.3295 -  from nob[rule_format, where j="1", OF one] pi show ?case by simp
 27.3296 -next
 27.3297 -  case (4 c e)  
 27.3298 -  hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 27.3299 -    and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> - ?N i e + real j"
 27.3300 -    by simp+
 27.3301 -  {assume "real (c*i) \<noteq> - ?N i e + real (c*d)"
 27.3302 -    with numbound0_I[OF nb, where bs="bs" and b="real i - real d" and b'="real i"]
 27.3303 -    have ?case by (simp add: ring_simps)}
 27.3304 -  moreover
 27.3305 -  {assume pi: "real (c*i) = - ?N i e + real (c*d)"
 27.3306 -    from mult_strict_left_mono[OF dp cp] have d: "(c*d) \<in> {1 .. c*d}" by simp
 27.3307 -    from nob[rule_format, where j="c*d", OF d] pi have ?case by simp }
 27.3308 -  ultimately show ?case by blast
 27.3309 -next
 27.3310 -  case (5 c e) hence cp: "c > 0" by simp
 27.3311 -  from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] 
 27.3312 -    real_of_int_mult]
 27.3313 -  show ?case using prems dp 
 27.3314 -    by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] 
 27.3315 -      ring_simps)
 27.3316 -next
 27.3317 -  case (6 c e)  hence cp: "c > 0" by simp
 27.3318 -  from prems mult_strict_left_mono[OF dp cp, simplified real_of_int_less_iff[symmetric] 
 27.3319 -    real_of_int_mult]
 27.3320 -  show ?case using prems dp 
 27.3321 -    by (simp add: add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] 
 27.3322 -      ring_simps)
 27.3323 -next
 27.3324 -  case (7 c e) hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 27.3325 -    and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> - ?N i e + real j"
 27.3326 -    and pi: "real (c*i) + ?N i e > 0" and cp': "real c >0"
 27.3327 -    by simp+
 27.3328 -  let ?fe = "floor (?N i e)"
 27.3329 -  from pi cp have th:"(real i +?N i e / real c)*real c > 0" by (simp add: ring_simps)
 27.3330 -  from pi ei[simplified isint_iff] have "real (c*i + ?fe) > real (0::int)" by simp
 27.3331 -  hence pi': "c*i + ?fe > 0" by (simp only: real_of_int_less_iff[symmetric])
 27.3332 -  have "real (c*i) + ?N i e > real (c*d) \<or> real (c*i) + ?N i e \<le> real (c*d)" by auto
 27.3333 -  moreover
 27.3334 -  {assume "real (c*i) + ?N i e > real (c*d)" hence ?case
 27.3335 -      by (simp add: ring_simps 
 27.3336 -	numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} 
 27.3337 -  moreover 
 27.3338 -  {assume H:"real (c*i) + ?N i e \<le> real (c*d)"
 27.3339 -    with ei[simplified isint_iff] have "real (c*i + ?fe) \<le> real (c*d)" by simp
 27.3340 -    hence pid: "c*i + ?fe \<le> c*d" by (simp only: real_of_int_le_iff)
 27.3341 -    with pi' have "\<exists> j1\<in> {1 .. c*d}. c*i + ?fe = j1" by auto
 27.3342 -    hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) = - ?N i e + real j1" 
 27.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)
 27.3344 -    with nob  have ?case by blast }
 27.3345 -  ultimately show ?case by blast
 27.3346 -next
 27.3347 -  case (8 c e)  hence cp: "c >0" and nb: "numbound0 e" and ei: "isint e (real i#bs)"
 27.3348 -    and nob: "\<forall> j\<in> {1 .. c*d}. real (c*i) \<noteq> - 1 - ?N i e + real j"
 27.3349 -    and pi: "real (c*i) + ?N i e \<ge> 0" and cp': "real c >0"
 27.3350 -    by simp+
 27.3351 -  let ?fe = "floor (?N i e)"
 27.3352 -  from pi cp have th:"(real i +?N i e / real c)*real c \<ge> 0" by (simp add: ring_simps)
 27.3353 -  from pi ei[simplified isint_iff] have "real (c*i + ?fe) \<ge> real (0::int)" by simp
 27.3354 -  hence pi': "c*i + 1 + ?fe \<ge> 1" by (simp only: real_of_int_le_iff[symmetric])
 27.3355 -  have "real (c*i) + ?N i e \<ge> real (c*d) \<or> real (c*i) + ?N i e < real (c*d)" by auto
 27.3356 -  moreover
 27.3357 -  {assume "real (c*i) + ?N i e \<ge> real (c*d)" hence ?case
 27.3358 -      by (simp add: ring_simps 
 27.3359 -	numbound0_I[OF nb,where bs="bs" and b="real i - real d" and b'="real i"])} 
 27.3360 -  moreover 
 27.3361 -  {assume H:"real (c*i) + ?N i e < real (c*d)"
 27.3362 -    with ei[simplified isint_iff] have "real (c*i + ?fe) < real (c*d)" by simp
 27.3363 -    hence pid: "c*i + 1 + ?fe \<le> c*d" by (simp only: real_of_int_le_iff)
 27.3364 -    with pi' have "\<exists> j1\<in> {1 .. c*d}. c*i + 1+ ?fe = j1" by auto
 27.3365 -    hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) + 1= - ?N i e + real j1"
 27.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) 
 27.3367 -    hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) = (- ?N i e + real j1) - 1"
 27.3368 -      by (simp only: ring_simps diff_def[symmetric])
 27.3369 -        hence "\<exists> j1\<in> {1 .. c*d}. real (c*i) = - 1 - ?N i e + real j1"
 27.3370 -	  by (simp only: add_ac diff_def)
 27.3371 -    with nob  have ?case by blast }
 27.3372 -  ultimately show ?case by blast
 27.3373 -next
 27.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+
 27.3375 -    let ?e = "Inum (real i # bs) e"
 27.3376 -    from prems have "isint e (real i #bs)"  by simp 
 27.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"]
 27.3378 -      by (simp add: isint_iff)
 27.3379 -    from prems have id: "j dvd d" by simp
 27.3380 -    from ie[symmetric] have "?p i = (real j rdvd real (c*i+ floor ?e))" by simp
 27.3381 -    also have "\<dots> = (j dvd c*i + floor ?e)" 
 27.3382 -      using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp
 27.3383 -    also have "\<dots> = (j dvd c*i - c*d + floor ?e)" 
 27.3384 -      using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp
 27.3385 -    also have "\<dots> = (real j rdvd real (c*i - c*d + floor ?e))" 
 27.3386 -      using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified]
 27.3387 -      ie by simp
 27.3388 -    also have "\<dots> = (real j rdvd real (c*(i - d)) + ?e)" 
 27.3389 -      using ie by (simp add:ring_simps)
 27.3390 -    finally show ?case 
 27.3391 -      using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p 
 27.3392 -      by (simp add: ring_simps)
 27.3393 -next
 27.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+
 27.3395 -    let ?e = "Inum (real i # bs) e"
 27.3396 -    from prems have "isint e (real i #bs)"  by simp 
 27.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"]
 27.3398 -      by (simp add: isint_iff)
 27.3399 -    from prems have id: "j dvd d" by simp
 27.3400 -    from ie[symmetric] have "?p i = (\<not> (real j rdvd real (c*i+ floor ?e)))" by simp
 27.3401 -    also have "\<dots> = Not (j dvd c*i + floor ?e)" 
 27.3402 -      using int_rdvd_iff [where i="j" and t="c*i+ floor ?e"] by simp
 27.3403 -    also have "\<dots> = Not (j dvd c*i - c*d + floor ?e)" 
 27.3404 -      using dvd_period[OF id, where x="c*i" and c="-c" and t="floor ?e"] by simp
 27.3405 -    also have "\<dots> = Not (real j rdvd real (c*i - c*d + floor ?e))" 
 27.3406 -      using int_rdvd_iff[where i="j" and t="(c*i - c*d + floor ?e)",symmetric, simplified]
 27.3407 -      ie by simp
 27.3408 -    also have "\<dots> = Not (real j rdvd real (c*(i - d)) + ?e)" 
 27.3409 -      using ie by (simp add:ring_simps)
 27.3410 -    finally show ?case 
 27.3411 -      using numbound0_I[OF bn,where b="real i - real d" and b'="real i" and bs="bs"] p 
 27.3412 -      by (simp add: ring_simps)
 27.3413 -qed(auto simp add: numbound0_I[where bs="bs" and b="real i - real d" and b'="real i"] nth_pos2)
 27.3414 -
 27.3415 -lemma \<sigma>_nb: assumes lp: "iszlfm p (a#bs)" and nb: "numbound0 t"
 27.3416 -  shows "bound0 (\<sigma> p k t)"
 27.3417 -  using \<sigma>\<rho>_nb[OF lp nb] nb by (simp add: \<sigma>_def)
 27.3418 -  
 27.3419 -lemma \<rho>':   assumes lp: "iszlfm p (a #bs)"
 27.3420 -  and d: "d\<delta> p d"
 27.3421 -  and dp: "d > 0"
 27.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)")
 27.3423 -proof(clarify)
 27.3424 -  fix x 
 27.3425 -  assume nob1:"?b x" and px: "?P x" 
 27.3426 -  from iszlfm_gen[OF lp, rule_format, where y="real x"] have lp': "iszlfm p (real x#bs)".
 27.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" 
 27.3428 -  proof(clarify)
 27.3429 -    fix e c j assume ecR: "(e,c) \<in> set (\<rho> p)" and jD: "j\<in> {1 .. c*d}"
 27.3430 -      and cx: "real (c*x) = Inum (real x#bs) e + real j"
 27.3431 -    let ?e = "Inum (real x#bs) e"
 27.3432 -    let ?fe = "floor ?e"
 27.3433 -    from \<rho>_l[OF lp'] ecR have ei:"isint e (real x#bs)" and cp:"c>0" and nb:"numbound0 e"
 27.3434 -      by auto
 27.3435 -    from numbound0_gen [OF nb ei, rule_format,where y="a"] have "isint e (a#bs)" .
 27.3436 -    from cx ei[simplified isint_iff] have "real (c*x) = real (?fe + j)" by simp
 27.3437 -    hence cx: "c*x = ?fe + j" by (simp only: real_of_int_inject)
 27.3438 -    hence cdej:"c dvd ?fe + j" by (simp add: dvd_def) (rule_tac x="x" in exI, simp)
 27.3439 -    hence "real c rdvd real (?fe + j)" by (simp only: int_rdvd_iff)
 27.3440 -    hence rcdej: "real c rdvd ?e + real j" by (simp add: ei[simplified isint_iff])
 27.3441 -    from cx have "(c*x) div c = (?fe + j) div c" by simp
 27.3442 -    with cp have "x = (?fe + j) div c" by simp
 27.3443 -    with px have th: "?P ((?fe + j) div c)" by auto
 27.3444 -    from cp have cp': "real c > 0" by simp
 27.3445 -    from cdej have cdej': "c dvd floor (Inum (real x#bs) (Add e (C j)))" by simp
 27.3446 -    from nb have nb': "numbound0 (Add e (C j))" by simp
 27.3447 -    have ji: "isint (C j) (real x#bs)" by (simp add: isint_def)
 27.3448 -    from isint_add[OF ei ji] have ei':"isint (Add e (C j)) (real x#bs)" .
 27.3449 -    from th \<sigma>\<rho>[where b'="real x", OF lp' cp' nb' ei' cdej',symmetric]
 27.3450 -    have "Ifm (real x#bs) (\<sigma>\<rho> p (Add e (C j), c))" by simp
 27.3451 -    with rcdej have th: "Ifm (real x#bs) (\<sigma> p c (Add e (C j)))" by (simp add: \<sigma>_def)
 27.3452 -    from th bound0_I[OF \<sigma>_nb[OF lp nb', where k="c"],where bs="bs" and b="real x" and b'="a"]
 27.3453 -    have "Ifm (a#bs) (\<sigma> p c (Add e (C j)))" by blast
 27.3454 -      with ecR jD nob1    show "False" by blast
 27.3455 -  qed
 27.3456 -  from \<rho>[OF lp' px d dp nob] show "?P (x -d )" . 
 27.3457 -qed
 27.3458 -
 27.3459 -
 27.3460 -lemma rl_thm: 
 27.3461 -  assumes lp: "iszlfm p (real (i::int)#bs)"
 27.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)))))"
 27.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))" 
 27.3464 -    is "?lhs = (?MD \<or> ?RD)"  is "?lhs = ?rhs")
 27.3465 -proof-
 27.3466 -  let ?d= "\<delta> p"
 27.3467 -  from \<delta>[OF lp] have d:"d\<delta> p ?d" and dp: "?d > 0" by auto
 27.3468 -  { assume H:"?MD" hence th:"\<exists> (x::int). ?MP x" by blast
 27.3469 -    from H minusinf_ex[OF lp th] have ?thesis  by blast}
 27.3470 -  moreover
 27.3471 -  { fix e c j assume exR:"(e,c) \<in> ?R" and jD:"j\<in> {1 .. c*?d}" and spx:"?SP c e j"
 27.3472 -    from exR \<rho>_l[OF lp] have nb: "numbound0 e" and ei:"isint e (real i#bs)" and cp: "c > 0"
 27.3473 -      by auto
 27.3474 -    have "isint (C j) (real i#bs)" by (simp add: isint_iff)
 27.3475 -    with isint_add[OF numbound0_gen[OF nb ei,rule_format, where y="real i"]]
 27.3476 -    have eji:"isint (Add e (C j)) (real i#bs)" by simp
 27.3477 -    from nb have nb': "numbound0 (Add e (C j))" by simp
 27.3478 -    from spx bound0_I[OF \<sigma>_nb[OF lp nb', where k="c"], where bs="bs" and b="a" and b'="real i"]
 27.3479 -    have spx': "Ifm (real i # bs) (\<sigma> p c (Add e (C j)))" by blast
 27.3480 -    from spx' have rcdej:"real c rdvd (Inum (real i#bs) (Add e (C j)))" 
 27.3481 -      and sr:"Ifm (real i#bs) (\<sigma>\<rho> p (Add e (C j),c))" by (simp add: \<sigma>_def)+
 27.3482 -    from rcdej eji[simplified isint_iff] 
 27.3483 -    have "real c rdvd real (floor (Inum (real i#bs) (Add e (C j))))" by simp
 27.3484 -    hence cdej:"c dvd floor (Inum (real i#bs) (Add e (C j)))" by (simp only: int_rdvd_iff)
 27.3485 -    from cp have cp': "real c > 0" by simp
 27.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)"
 27.3487 -      by (simp add: \<sigma>_def)
 27.3488 -    hence ?lhs by blast
 27.3489 -    with exR jD spx have ?thesis by blast}
 27.3490 -  moreover
 27.3491 -  { fix x assume px: "?P x" and nob: "\<not> ?RD"
 27.3492 -    from iszlfm_gen [OF lp,rule_format, where y="a"] have lp':"iszlfm p (a#bs)" .
 27.3493 -    from \<rho>'[OF lp' d dp, rule_format, OF nob] have th:"\<forall> x. ?P x \<longrightarrow> ?P (x - ?d)" by blast
 27.3494 -    from minusinf_inf[OF lp] obtain z where z:"\<forall> x<z. ?MP x = ?P x" by blast
 27.3495 -    have zp: "abs (x - z) + 1 \<ge> 0" by arith
 27.3496 -    from decr_lemma[OF dp,where x="x" and z="z"] 
 27.3497 -      decr_mult_lemma[OF dp th zp, rule_format, OF px] z have th:"\<exists> x. ?MP x" by auto
 27.3498 -    with minusinf_bex[OF lp] px nob have ?thesis by blast}
 27.3499 -  ultimately show ?thesis by blast
 27.3500 -qed
 27.3501 -
 27.3502 -lemma mirror_\<alpha>\<rho>:   assumes lp: "iszlfm p (a#bs)"
 27.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))"
 27.3504 -using lp
 27.3505 -by (induct p rule: mirror.induct, simp_all add: split_def image_Un )
 27.3506 -  
 27.3507 -text {* The @{text "\<real>"} part*}
 27.3508 -
 27.3509 -text{* Linearity for fm where Bound 0 ranges over @{text "\<real>"}*}
 27.3510 -consts
 27.3511 -  isrlfm :: "fm \<Rightarrow> bool"   (* Linearity test for fm *)
 27.3512 -recdef isrlfm "measure size"
 27.3513 -  "isrlfm (And p q) = (isrlfm p \<and> isrlfm q)" 
 27.3514 -  "isrlfm (Or p q) = (isrlfm p \<and> isrlfm q)" 
 27.3515 -  "isrlfm (Eq  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 27.3516 -  "isrlfm (NEq (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 27.3517 -  "isrlfm (Lt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 27.3518 -  "isrlfm (Le  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 27.3519 -  "isrlfm (Gt  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 27.3520 -  "isrlfm (Ge  (CN 0 c e)) = (c>0 \<and> numbound0 e)"
 27.3521 -  "isrlfm p = (isatom p \<and> (bound0 p))"
 27.3522 -
 27.3523 -constdefs fp :: "fm \<Rightarrow> int \<Rightarrow> num \<Rightarrow> int \<Rightarrow> fm"
 27.3524 -  "fp p n s j \<equiv> (if n > 0 then 
 27.3525 -            (And p (And (Ge (CN 0 n (Sub s (Add (Floor s) (C j)))))
 27.3526 -                        (Lt (CN 0 n (Sub s (Add (Floor s) (C (j+1))))))))
 27.3527 -            else 
 27.3528 -            (And p (And (Le (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C j))))) 
 27.3529 -                        (Gt (CN 0 (-n) (Add (Neg s) (Add (Floor s) (C (j + 1)))))))))"
 27.3530 -
 27.3531 -  (* splits the bounded from the unbounded part*)
 27.3532 -consts rsplit0 :: "num \<Rightarrow> (fm \<times> int \<times> num) list" 
 27.3533 -recdef rsplit0 "measure num_size"
 27.3534 -  "rsplit0 (Bound 0) = [(T,1,C 0)]"
 27.3535 -  "rsplit0 (Add a b) = (let acs = rsplit0 a ; bcs = rsplit0 b 
 27.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])"
 27.3537 -  "rsplit0 (Sub a b) = rsplit0 (Add a (Neg b))"
 27.3538 -  "rsplit0 (Neg a) = map (\<lambda> (p,n,s). (p,-n,Neg s)) (rsplit0 a)"
 27.3539 -  "rsplit0 (Floor a) = foldl (op @) [] (map 
 27.3540 -      (\<lambda> (p,n,s). if n=0 then [(p,0,Floor s)]
 27.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))))
 27.3542 -       (rsplit0 a))"
 27.3543 -  "rsplit0 (CN 0 c a) = map (\<lambda> (p,n,s). (p,n+c,s)) (rsplit0 a)"
 27.3544 -  "rsplit0 (CN m c a) = map (\<lambda> (p,n,s). (p,n,CN m c s)) (rsplit0 a)"
 27.3545 -  "rsplit0 (CF c t s) = rsplit0 (Add (Mul c (Floor t)) s)"
 27.3546 -  "rsplit0 (Mul c a) = map (\<lambda> (p,n,s). (p,c*n,Mul c s)) (rsplit0 a)"
 27.3547 -  "rsplit0 t = [(T,0,t)]"
 27.3548 -
 27.3549 -lemma not_rl[simp]: "isrlfm p \<Longrightarrow> isrlfm (not p)"
 27.3550 -  by (induct p rule: isrlfm.induct, auto)
 27.3551 -lemma conj_rl[simp]: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (conj p q)"
 27.3552 -  using conj_def by (cases p, auto)
 27.3553 -lemma disj_rl[simp]: "isrlfm p \<Longrightarrow> isrlfm q \<Longrightarrow> isrlfm (disj p q)"
 27.3554 -  using disj_def by (cases p, auto)
 27.3555 -
 27.3556 -
 27.3557 -lemma rsplit0_cs:
 27.3558 -  shows "\<forall> (p,n,s) \<in> set (rsplit0 t). 
 27.3559 -  (Ifm (x#bs) p \<longrightarrow>  (Inum (x#bs) t = Inum (x#bs) (CN 0 n s))) \<and> numbound0 s \<and> isrlfm p" 
 27.3560 -  (is "\<forall> (p,n,s) \<in> ?SS t. (?I p \<longrightarrow> ?N t = ?N (CN 0 n s)) \<and> _ \<and> _ ")
 27.3561 -proof(induct t rule: rsplit0.induct)
 27.3562 -  case (5 a) 
 27.3563 -  let ?p = "\<lambda> (p,n,s) j. fp p n s j"
 27.3564 -  let ?f = "(\<lambda> (p,n,s) j. (?p (p,n,s) j, (0::int),Add (Floor s) (C j)))"
 27.3565 -  let ?J = "\<lambda> n. if n>0 then iupt (0,n) else iupt (n,0)"
 27.3566 -  let ?ff=" (\<lambda> (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))"
 27.3567 -  have int_cases: "\<forall> (i::int). i= 0 \<or> i < 0 \<or> i > 0" by arith
 27.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)))) = 
 27.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
 27.3570 -  have U2': "\<forall> (p,n,s) \<in> {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0}. 
 27.3571 -    ?ff (p,n,s) = map (?f(p,n,s)) (iupt(0,n))" by auto
 27.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)))) = 
 27.3573 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). 
 27.3574 -    set (map (?f(p,n,s)) (iupt(0,n)))))"
 27.3575 -  proof-
 27.3576 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 27.3577 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 27.3578 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 27.3579 -      by (auto simp add: split_def)
 27.3580 -  qed
 27.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))"
 27.3582 -    by auto
 27.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)))) = 
 27.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)))))"
 27.3585 -      proof-
 27.3586 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 27.3587 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 27.3588 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 27.3589 -      by (auto simp add: split_def)
 27.3590 -  qed
 27.3591 -  have "?SS (Floor a) = UNION (?SS a) (\<lambda>x. set (?ff x))" 
 27.3592 -    by (auto simp add: foldl_conv_concat)
 27.3593 -  also have "\<dots> = UNION (?SS a) (\<lambda> (p,n,s). set (?ff (p,n,s)))" by auto
 27.3594 -  also have "\<dots> = 
 27.3595 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 27.3596 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 27.3597 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (?ff (p,n,s)))))" 
 27.3598 -    using int_cases[rule_format] by blast
 27.3599 -  also have "\<dots> =  
 27.3600 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set [(p,0,Floor s)])) Un 
 27.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 
 27.3602 -   (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). 
 27.3603 -    set (map (?f(p,n,s)) (iupt(n,0))))))" by (simp only: U1 U2 U3)
 27.3604 -  also have "\<dots> =  
 27.3605 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 27.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 
 27.3607 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). (?f(p,n,s)) ` {n .. 0})))"
 27.3608 -    by (simp only: set_map iupt_set set.simps)
 27.3609 -  also have "\<dots> =   
 27.3610 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 27.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 
 27.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
 27.3613 -  finally 
 27.3614 -  have FS: "?SS (Floor a) =   
 27.3615 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 27.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 
 27.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
 27.3618 -  show ?case
 27.3619 -    proof(simp only: FS, clarsimp simp del: Ifm.simps Inum.simps, -)
 27.3620 -      fix p n s
 27.3621 -      let ?ths = "(?I p \<longrightarrow> (?N (Floor a) = ?N (CN 0 n s))) \<and> numbound0 s \<and> isrlfm p"
 27.3622 -      assume "(\<exists>ba. (p, 0, ba) \<in> set (rsplit0 a) \<and> n = 0 \<and> s = Floor ba) \<or>
 27.3623 -       (\<exists>ab ac ba.
 27.3624 -           (ab, ac, ba) \<in> set (rsplit0 a) \<and>
 27.3625 -           0 < ac \<and>
 27.3626 -           (\<exists>j. p = fp ab ac ba j \<and>
 27.3627 -                n = 0 \<and> s = Add (Floor ba) (C j) \<and> 0 \<le> j \<and> j \<le> ac)) \<or>
 27.3628 -       (\<exists>ab ac ba.
 27.3629 -           (ab, ac, ba) \<in> set (rsplit0 a) \<and>
 27.3630 -           ac < 0 \<and>
 27.3631 -           (\<exists>j. p = fp ab ac ba j \<and>
 27.3632 -                n = 0 \<and> s = Add (Floor ba) (C j) \<and> ac \<le> j \<and> j \<le> 0))"
 27.3633 -      moreover 
 27.3634 -      {fix s'
 27.3635 -	assume "(p, 0, s') \<in> ?SS a" and "n = 0" and "s = Floor s'"
 27.3636 -	hence ?ths using prems by auto}
 27.3637 -      moreover
 27.3638 -      {	fix p' n' s' j
 27.3639 -	assume pns: "(p', n', s') \<in> ?SS a" 
 27.3640 -	  and np: "0 < n'" 
 27.3641 -	  and p_def: "p = ?p (p',n',s') j" 
 27.3642 -	  and n0: "n = 0" 
 27.3643 -	  and s_def: "s = (Add (Floor s') (C j))" 
 27.3644 -	  and jp: "0 \<le> j" and jn: "j \<le> n'"
 27.3645 -	from prems pns have H:"(Ifm ((x\<Colon>real) # (bs\<Colon>real list)) p' \<longrightarrow>
 27.3646 -          Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \<and>
 27.3647 -          numbound0 s' \<and> isrlfm p'" by blast
 27.3648 -	hence nb: "numbound0 s'" by simp
 27.3649 -	from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numsub_nb)
 27.3650 -	let ?nxs = "CN 0 n' s'"
 27.3651 -	let ?l = "floor (?N s') + j"
 27.3652 -	from H 
 27.3653 -	have "?I (?p (p',n',s') j) \<longrightarrow> 
 27.3654 -	  (((?N ?nxs \<ge> real ?l) \<and> (?N ?nxs < real (?l + 1))) \<and> (?N a = ?N ?nxs ))" 
 27.3655 -	  by (simp add: fp_def np ring_simps numsub numadd numfloor)
 27.3656 -	also have "\<dots> \<longrightarrow> ((floor (?N ?nxs) = ?l) \<and> (?N a = ?N ?nxs ))"
 27.3657 -	  using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp
 27.3658 -	moreover
 27.3659 -	have "\<dots> \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))" by simp
 27.3660 -	ultimately have "?I (?p (p',n',s') j) \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))"
 27.3661 -	  by blast
 27.3662 -	with s_def n0 p_def nb nf have ?ths by auto}
 27.3663 -      moreover
 27.3664 -      {fix p' n' s' j
 27.3665 -	assume pns: "(p', n', s') \<in> ?SS a" 
 27.3666 -	  and np: "n' < 0" 
 27.3667 -	  and p_def: "p = ?p (p',n',s') j" 
 27.3668 -	  and n0: "n = 0" 
 27.3669 -	  and s_def: "s = (Add (Floor s') (C j))" 
 27.3670 -	  and jp: "n' \<le> j" and jn: "j \<le> 0"
 27.3671 -	from prems pns have H:"(Ifm ((x\<Colon>real) # (bs\<Colon>real list)) p' \<longrightarrow>
 27.3672 -          Inum (x # bs) a = Inum (x # bs) (CN 0 n' s')) \<and>
 27.3673 -          numbound0 s' \<and> isrlfm p'" by blast
 27.3674 -	hence nb: "numbound0 s'" by simp
 27.3675 -	from H have nf: "isrlfm (?p (p',n',s') j)" using fp_def np by (simp add: numneg_nb)
 27.3676 -	let ?nxs = "CN 0 n' s'"
 27.3677 -	let ?l = "floor (?N s') + j"
 27.3678 -	from H 
 27.3679 -	have "?I (?p (p',n',s') j) \<longrightarrow> 
 27.3680 -	  (((?N ?nxs \<ge> real ?l) \<and> (?N ?nxs < real (?l + 1))) \<and> (?N a = ?N ?nxs ))" 
 27.3681 -	  by (simp add: np fp_def ring_simps numneg numfloor numadd numsub)
 27.3682 -	also have "\<dots> \<longrightarrow> ((floor (?N ?nxs) = ?l) \<and> (?N a = ?N ?nxs ))"
 27.3683 -	  using floor_int_eq[where x="?N ?nxs" and n="?l"] by simp
 27.3684 -	moreover
 27.3685 -	have "\<dots> \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))"  by simp
 27.3686 -	ultimately have "?I (?p (p',n',s') j) \<longrightarrow> (?N (Floor a) = ?N ((Add (Floor s') (C j))))"
 27.3687 -	  by blast
 27.3688 -	with s_def n0 p_def nb nf have ?ths by auto}
 27.3689 -      ultimately show ?ths by auto
 27.3690 -    qed
 27.3691 -next
 27.3692 -  case (3 a b) then show ?case
 27.3693 -  apply auto
 27.3694 -  apply (erule_tac x = "(aa, aaa, ba)" in ballE) apply simp_all
 27.3695 -  apply (erule_tac x = "(ab, ac, baa)" in ballE) apply simp_all
 27.3696 -  done
 27.3697 -qed (auto simp add: Let_def split_def ring_simps conj_rl)
 27.3698 -
 27.3699 -lemma real_in_int_intervals: 
 27.3700 -  assumes xb: "real m \<le> x \<and> x < real ((n::int) + 1)"
 27.3701 -  shows "\<exists> j\<in> {m.. n}. real j \<le> x \<and> x < real (j+1)" (is "\<exists> j\<in> ?N. ?P j")
 27.3702 -by (rule bexI[where P="?P" and x="floor x" and A="?N"]) 
 27.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"]])
 27.3704 -
 27.3705 -lemma rsplit0_complete:
 27.3706 -  assumes xp:"0 \<le> x" and x1:"x < 1"
 27.3707 -  shows "\<exists> (p,n,s) \<in> set (rsplit0 t). Ifm (x#bs) p" (is "\<exists> (p,n,s) \<in> ?SS t. ?I p")
 27.3708 -proof(induct t rule: rsplit0.induct)
 27.3709 -  case (2 a b) 
 27.3710 -  from prems have "\<exists> (pa,na,sa) \<in> ?SS a. ?I pa" by auto
 27.3711 -  then obtain "pa" "na" "sa" where pa: "(pa,na,sa)\<in> ?SS a \<and> ?I pa" by blast
 27.3712 -  from prems have "\<exists> (pb,nb,sb) \<in> ?SS b. ?I pb" by auto
 27.3713 -  then obtain "pb" "nb" "sb" where pb: "(pb,nb,sb)\<in> ?SS b \<and> ?I pb" by blast
 27.3714 -  from pa pb have th: "((pa,na,sa),(pb,nb,sb)) \<in> set[(x,y). x\<leftarrow>rsplit0 a, y\<leftarrow>rsplit0 b]"
 27.3715 -    by (auto)
 27.3716 -  let ?f="(\<lambda> ((p,n,t),(q,m,s)). (And p q, n+m, Add t s))"
 27.3717 -  from imageI[OF th, where f="?f"] have "?f ((pa,na,sa),(pb,nb,sb)) \<in> ?SS (Add a b)"
 27.3718 -    by (simp add: Let_def)
 27.3719 -  hence "(And pa pb, na +nb, Add sa sb) \<in> ?SS (Add a b)" by simp
 27.3720 -  moreover from pa pb have "?I (And pa pb)" by simp
 27.3721 -  ultimately show ?case by blast
 27.3722 -next
 27.3723 -  case (5 a) 
 27.3724 -  let ?p = "\<lambda> (p,n,s) j. fp p n s j"
 27.3725 -  let ?f = "(\<lambda> (p,n,s) j. (?p (p,n,s) j, (0::int),(Add (Floor s) (C j))))"
 27.3726 -  let ?J = "\<lambda> n. if n>0 then iupt (0,n) else iupt (n,0)"
 27.3727 -  let ?ff=" (\<lambda> (p,n,s). if n= 0 then [(p,0,Floor s)] else map (?f (p,n,s)) (?J n))"
 27.3728 -  have int_cases: "\<forall> (i::int). i= 0 \<or> i < 0 \<or> i > 0" by arith
 27.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
 27.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))"
 27.3731 -    by auto
 27.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)))))"
 27.3733 -  proof-
 27.3734 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 27.3735 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 27.3736 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 27.3737 -      by (auto simp add: split_def)
 27.3738 -  qed
 27.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))"
 27.3740 -    by auto
 27.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)))))"
 27.3742 -  proof-
 27.3743 -    fix M :: "('a\<times>'b\<times>'c) set" and f :: "('a\<times>'b\<times>'c) \<Rightarrow> 'd list" and g
 27.3744 -    assume "\<forall> (a,b,c) \<in> M. f (a,b,c) = g a b c"
 27.3745 -    thus "(UNION M (\<lambda> (a,b,c). set (f (a,b,c)))) = (UNION M (\<lambda> (a,b,c). set (g a b c)))"
 27.3746 -      by (auto simp add: split_def)
 27.3747 -  qed
 27.3748 -
 27.3749 -  have "?SS (Floor a) = UNION (?SS a) (\<lambda>x. set (?ff x))" by (auto simp add: foldl_conv_concat) 
 27.3750 -  also have "\<dots> = UNION (?SS a) (\<lambda> (p,n,s). set (?ff (p,n,s)))" by auto
 27.3751 -  also have "\<dots> = 
 27.3752 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 27.3753 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n>0} (\<lambda> (p,n,s). set (?ff (p,n,s)))) Un 
 27.3754 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). set (?ff (p,n,s)))))" 
 27.3755 -    using int_cases[rule_format] by blast
 27.3756 -  also have "\<dots> =  
 27.3757 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). set [(p,0,Floor s)])) Un 
 27.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 
 27.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)
 27.3760 -  also have "\<dots> =  
 27.3761 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 27.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 
 27.3763 -    (UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n<0} (\<lambda> (p,n,s). (?f(p,n,s)) ` {n .. 0})))"
 27.3764 -    by (simp only: set_map iupt_set set.simps)
 27.3765 -  also have "\<dots> =   
 27.3766 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 27.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 
 27.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
 27.3769 -  finally 
 27.3770 -  have FS: "?SS (Floor a) =   
 27.3771 -    ((UNION {(p,n,s). (p,n,s) \<in> ?SS a \<and> n=0} (\<lambda> (p,n,s). {(p,0,Floor s)})) Un 
 27.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 
 27.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
 27.3774 -  from prems have "\<exists> (p,n,s) \<in> ?SS a. ?I p" by auto
 27.3775 -  then obtain "p" "n" "s" where pns: "(p,n,s) \<in> ?SS a \<and> ?I p" by blast
 27.3776 -  let ?N = "\<lambda> t. Inum (x#bs) t"
 27.3777 -  from rsplit0_cs[rule_format] pns have ans:"(?N a = ?N (CN 0 n s)) \<and> numbound0 s \<and> isrlfm p"
 27.3778 -    by auto
 27.3779 -  
 27.3780 -  have "n=0 \<or> n >0 \<or> n <0" by arith
 27.3781 -  moreover {assume "n=0" hence ?case using pns by (simp only: FS) auto }
 27.3782 -  moreover
 27.3783 -  {
 27.3784 -    assume np: "n > 0"
 27.3785 -    from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) \<le> ?N s" by simp
 27.3786 -    also from mult_left_mono[OF xp] np have "?N s \<le> real n * x + ?N s" by simp
 27.3787 -    finally have "?N (Floor s) \<le> real n * x + ?N s" .
 27.3788 -    moreover
 27.3789 -    {from mult_strict_left_mono[OF x1] np 
 27.3790 -      have "real n *x + ?N s < real n + ?N s" by simp
 27.3791 -      also from real_of_int_floor_add_one_gt[where r="?N s"] 
 27.3792 -      have "\<dots> < real n + ?N (Floor s) + 1" by simp
 27.3793 -      finally have "real n *x + ?N s < ?N (Floor s) + real (n+1)" by simp}
 27.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
 27.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
 27.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
 27.3797 -    
 27.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"
 27.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)"]) 
 27.3800 -    hence "\<exists> j\<in> {0.. n}. ?I (?p (p,n,s) j)"
 27.3801 -      using pns by (simp add: fp_def np ring_simps numsub numadd)
 27.3802 -    then obtain "j" where j_def: "j\<in> {0 .. n} \<and> ?I (?p (p,n,s) j)" by blast
 27.3803 -    hence "\<exists>x \<in> {?p (p,n,s) j |j. 0\<le> j \<and> j \<le> n }. ?I x" by auto
 27.3804 -    hence ?case using pns 
 27.3805 -      by (simp only: FS,simp add: bex_Un) 
 27.3806 -    (rule disjI2, rule disjI1,rule exI [where x="p"],
 27.3807 -      rule exI [where x="n"],rule exI [where x="s"],simp_all add: np)
 27.3808 -  }
 27.3809 -  moreover
 27.3810 -  { assume nn: "n < 0" hence np: "-n >0" by simp
 27.3811 -    from real_of_int_floor_le[where r="?N s"] have "?N (Floor s) + 1 > ?N s" by simp
 27.3812 -    moreover from mult_left_mono_neg[OF xp] nn have "?N s \<ge> real n * x + ?N s" by simp
 27.3813 -    ultimately have "?N (Floor s) + 1 > real n * x + ?N s" by arith 
 27.3814 -    moreover
 27.3815 -    {from mult_strict_left_mono_neg[OF x1, where c="real n"] nn
 27.3816 -      have "real n *x + ?N s \<ge> real n + ?N s" by simp 
 27.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
 27.3818 -      ultimately have "real n *x + ?N s \<ge> ?N (Floor s) + real n" 
 27.3819 -	by (simp only: ring_simps)}
 27.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
 27.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
 27.3822 -    have th1: "\<forall> (a::real). (- a > 0) = (a < 0)" by auto
 27.3823 -    have th2: "\<forall> (a::real). (0 \<ge> - a) = (a \<ge> 0)" by auto
 27.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
 27.3825 -    
 27.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"
 27.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)"]) 
 27.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])
 27.3829 -    hence "\<exists> j\<in> {n.. 0}. ?I (?p (p,n,s) j)"
 27.3830 -      using pns by (simp add: fp_def nn diff_def add_ac mult_ac numfloor numadd numneg
 27.3831 -	del: diff_less_0_iff_less diff_le_0_iff_le) 
 27.3832 -    then obtain "j" where j_def: "j\<in> {n .. 0} \<and> ?I (?p (p,n,s) j)" by blast
 27.3833 -    hence "\<exists>x \<in> {?p (p,n,s) j |j. n\<le> j \<and> j \<le> 0 }. ?I x" by auto
 27.3834 -    hence ?case using pns 
 27.3835 -      by (simp only: FS,simp add: bex_Un)
 27.3836 -    (rule disjI2, rule disjI2,rule exI [where x="p"],
 27.3837 -      rule exI [where x="n"],rule exI [where x="s"],simp_all add: nn)
 27.3838 -  }
 27.3839 -  ultimately show ?case by blast
 27.3840 -qed (auto simp add: Let_def split_def)
 27.3841 -
 27.3842 -    (* Linearize a formula where Bound 0 ranges over [0,1) *)
 27.3843 -
 27.3844 -constdefs rsplit :: "(int \<Rightarrow> num \<Rightarrow> fm) \<Rightarrow> num \<Rightarrow> fm"
 27.3845 -  "rsplit f a \<equiv> foldr disj (map (\<lambda> (\<phi>, n, s). conj \<phi> (f n s)) (rsplit0 a)) F"
 27.3846 -
 27.3847 -lemma foldr_disj_map: "Ifm bs (foldr disj (map f xs) F) = (\<exists> x \<in> set xs. Ifm bs (f x))"
 27.3848 -by(induct xs, simp_all)
 27.3849 -
 27.3850 -lemma foldr_conj_map: "Ifm bs (foldr conj (map f xs) T) = (\<forall> x \<in> set xs. Ifm bs (f x))"
 27.3851 -by(induct xs, simp_all)
 27.3852 -
 27.3853 -lemma foldr_disj_map_rlfm: 
 27.3854 -  assumes lf: "\<forall> n s. numbound0 s \<longrightarrow> isrlfm (f n s)"
 27.3855 -  and \<phi>: "\<forall> (\<phi>,n,s) \<in> set xs. numbound0 s \<and> isrlfm \<phi>"
 27.3856 -  shows "isrlfm (foldr disj (map (\<lambda> (\<phi>, n, s). conj \<phi> (f n s)) xs) F)"
 27.3857 -using lf \<phi> by (induct xs, auto)
 27.3858 -
 27.3859 -lemma rsplit_ex: "Ifm bs (rsplit f a) = (\<exists> (\<phi>,n,s) \<in> set (rsplit0 a). Ifm bs (conj \<phi> (f n s)))"
 27.3860 -using foldr_disj_map[where xs="rsplit0 a"] rsplit_def by (simp add: split_def)
 27.3861 -
 27.3862 -lemma rsplit_l: assumes lf: "\<forall> n s. numbound0 s \<longrightarrow> isrlfm (f n s)"
 27.3863 -  shows "isrlfm (rsplit f a)"
 27.3864 -proof-
 27.3865 -  from rsplit0_cs[where t="a"] have th: "\<forall> (\<phi>,n,s) \<in> set (rsplit0 a). numbound0 s \<and> isrlfm \<phi>" by blast
 27.3866 -  from foldr_disj_map_rlfm[OF lf th] rsplit_def show ?thesis by simp
 27.3867 -qed
 27.3868 -
 27.3869 -lemma rsplit: 
 27.3870 -  assumes xp: "x \<ge> 0" and x1: "x < 1"
 27.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))"
 27.3872 -  shows "Ifm (x#bs) (rsplit f a) = Ifm (x#bs) (g a)"
 27.3873 -proof(auto)
 27.3874 -  let ?I = "\<lambda>x p. Ifm (x#bs) p"
 27.3875 -  let ?N = "\<lambda> x t. Inum (x#bs) t"
 27.3876 -  assume "?I x (rsplit f a)"
 27.3877 -  hence "\<exists> (\<phi>,n,s) \<in> set (rsplit0 a). ?I x (And \<phi> (f n s))" using rsplit_ex by simp
 27.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
 27.3879 -  hence \<phi>: "?I x \<phi>" and fns: "?I x (f n s)" by auto
 27.3880 -  from rsplit0_cs[where t="a" and bs="bs" and x="x", rule_format, OF fnsS] \<phi> 
 27.3881 -  have th: "(?N x a = ?N x (CN 0 n s)) \<and> numbound0 s" by auto
 27.3882 -  from f[rule_format, OF th] fns show "?I x (g a)" by simp
 27.3883 -next
 27.3884 -  let ?I = "\<lambda>x p. Ifm (x#bs) p"
 27.3885 -  let ?N = "\<lambda> x t. Inum (x#bs) t"
 27.3886 -  assume ga: "?I x (g a)"
 27.3887 -  from rsplit0_complete[OF xp x1, where bs="bs" and t="a"] 
 27.3888 -  obtain "\<phi>" "n" "s" where fnsS:"(\<phi>,n,s) \<in> set (rsplit0 a)" and fx: "?I x \<phi>" by blast
 27.3889 -  from rsplit0_cs[where t="a" and x="x" and bs="bs"] fnsS fx
 27.3890 -  have ans: "?N x a = ?N x (CN 0 n s)" and nb: "numbound0 s" by auto
 27.3891 -  with ga f have "?I x (f n s)" by auto
 27.3892 -  with rsplit_ex fnsS fx show "?I x (rsplit f a)" by auto
 27.3893 -qed
 27.3894 -
 27.3895 -definition lt :: "int \<Rightarrow> num \<Rightarrow> fm" where
 27.3896 -  lt_def: "lt c t = (if c = 0 then (Lt t) else if c > 0 then (Lt (CN 0 c t)) 
 27.3897 -                        else (Gt (CN 0 (-c) (Neg t))))"
 27.3898 -
 27.3899 -definition  le :: "int \<Rightarrow> num \<Rightarrow> fm" where
 27.3900 -  le_def: "le c t = (if c = 0 then (Le t) else if c > 0 then (Le (CN 0 c t)) 
 27.3901 -                        else (Ge (CN 0 (-c) (Neg t))))"
 27.3902 -
 27.3903 -definition  gt :: "int \<Rightarrow> num \<Rightarrow> fm" where
 27.3904 -  gt_def: "gt c t = (if c = 0 then (Gt t) else if c > 0 then (Gt (CN 0 c t)) 
 27.3905 -                        else (Lt (CN 0 (-c) (Neg t))))"
 27.3906 -
 27.3907 -definition  ge :: "int \<Rightarrow> num \<Rightarrow> fm" where
 27.3908 -  ge_def: "ge c t = (if c = 0 then (Ge t) else if c > 0 then (Ge (CN 0 c t)) 
 27.3909 -                        else (Le (CN 0 (-c) (Neg t))))"
 27.3910 -
 27.3911 -definition  eq :: "int \<Rightarrow> num \<Rightarrow> fm" where
 27.3912 -  eq_def: "eq c t = (if c = 0 then (Eq t) else if c > 0 then (Eq (CN 0 c t)) 
 27.3913 -                        else (Eq (CN 0 (-c) (Neg t))))"
 27.3914 -
 27.3915 -definition neq :: "int \<Rightarrow> num \<Rightarrow> fm" where
 27.3916 -  neq_def: "neq c t = (if c = 0 then (NEq t) else if c > 0 then (NEq (CN 0 c t)) 
 27.3917 -                        else (NEq (CN 0 (-c) (Neg t))))"
 27.3918 -
 27.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)"
 27.3920 -  (is "\<forall> a n s . ?N a = ?N (CN 0 n s) \<and> _\<longrightarrow> ?I (lt n s) = ?I (Lt a)")
 27.3921 -proof(clarify)
 27.3922 -  fix a n s
 27.3923 -  assume H: "?N a = ?N (CN 0 n s)"
 27.3924 -  show "?I (lt n s) = ?I (Lt a)" using H by (cases "n=0", (simp add: lt_def))
 27.3925 -  (cases "n > 0", simp_all add: lt_def ring_simps myless[rule_format, where b="0"])
 27.3926 -qed
 27.3927 -
 27.3928 -lemma lt_l: "isrlfm (rsplit lt a)"
 27.3929 -  by (rule rsplit_l[where f="lt" and a="a"], auto simp add: lt_def,
 27.3930 -    case_tac s, simp_all, case_tac "nat", simp_all)
 27.3931 -
 27.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)")
 27.3933 -proof(clarify)
 27.3934 -  fix a n s
 27.3935 -  assume H: "?N a = ?N (CN 0 n s)"
 27.3936 -  show "?I (le n s) = ?I (Le a)" using H by (cases "n=0", (simp add: le_def))
 27.3937 -  (cases "n > 0", simp_all add: le_def ring_simps myl[rule_format, where b="0"])
 27.3938 -qed
 27.3939 -
 27.3940 -lemma le_l: "isrlfm (rsplit le a)"
 27.3941 -  by (rule rsplit_l[where f="le" and a="a"], auto simp add: le_def) 
 27.3942 -(case_tac s, simp_all, case_tac "nat",simp_all)
 27.3943 -
 27.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)")
 27.3945 -proof(clarify)
 27.3946 -  fix a n s
 27.3947 -  assume H: "?N a = ?N (CN 0 n s)"
 27.3948 -  show "?I (gt n s) = ?I (Gt a)" using H by (cases "n=0", (simp add: gt_def))
 27.3949 -  (cases "n > 0", simp_all add: gt_def ring_simps myless[rule_format, where b="0"])
 27.3950 -qed
 27.3951 -lemma gt_l: "isrlfm (rsplit gt a)"
 27.3952 -  by (rule rsplit_l[where f="gt" and a="a"], auto simp add: gt_def) 
 27.3953 -(case_tac s, simp_all, case_tac "nat", simp_all)
 27.3954 -
 27.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)")
 27.3956 -proof(clarify)
 27.3957 -  fix a n s 
 27.3958 -  assume H: "?N a = ?N (CN 0 n s)"
 27.3959 -  show "?I (ge n s) = ?I (Ge a)" using H by (cases "n=0", (simp add: ge_def))
 27.3960 -  (cases "n > 0", simp_all add: ge_def ring_simps myl[rule_format, where b="0"])
 27.3961 -qed
 27.3962 -lemma ge_l: "isrlfm (rsplit ge a)"
 27.3963 -  by (rule rsplit_l[where f="ge" and a="a"], auto simp add: ge_def) 
 27.3964 -(case_tac s, simp_all, case_tac "nat", simp_all)
 27.3965 -
 27.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)")
 27.3967 -proof(clarify)
 27.3968 -  fix a n s 
 27.3969 -  assume H: "?N a = ?N (CN 0 n s)"
 27.3970 -  show "?I (eq n s) = ?I (Eq a)" using H by (auto simp add: eq_def ring_simps)
 27.3971 -qed
 27.3972 -lemma eq_l: "isrlfm (rsplit eq a)"
 27.3973 -  by (rule rsplit_l[where f="eq" and a="a"], auto simp add: eq_def) 
 27.3974 -(case_tac s, simp_all, case_tac"nat", simp_all)
 27.3975 -
 27.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)")
 27.3977 -proof(clarify)
 27.3978 -  fix a n s bs
 27.3979 -  assume H: "?N a = ?N (CN 0 n s)"
 27.3980 -  show "?I (neq n s) = ?I (NEq a)" using H by (auto simp add: neq_def ring_simps)
 27.3981 -qed
 27.3982 -
 27.3983 -lemma neq_l: "isrlfm (rsplit neq a)"
 27.3984 -  by (rule rsplit_l[where f="neq" and a="a"], auto simp add: neq_def) 
 27.3985 -(case_tac s, simp_all, case_tac"nat", simp_all)
 27.3986 -
 27.3987 -lemma small_le: 
 27.3988 -  assumes u0:"0 \<le> u" and u1: "u < 1"
 27.3989 -  shows "(-u \<le> real (n::int)) = (0 \<le> n)"
 27.3990 -using u0 u1  by auto
 27.3991 -
 27.3992 -lemma small_lt: 
 27.3993 -  assumes u0:"0 \<le> u" and u1: "u < 1"
 27.3994 -  shows "(real (n::int) < real (m::int) - u) = (n < m)"
 27.3995 -using u0 u1  by auto
 27.3996 -
 27.3997 -lemma rdvd01_cs: 
 27.3998 -  assumes up: "u \<ge> 0" and u1: "u<1" and np: "real n > 0"
 27.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")
 27.4000 -proof-
 27.4001 -  let ?ss = "s - real (floor s)"
 27.4002 -  from real_of_int_floor_add_one_gt[where r="s", simplified myless[rule_format,where a="s"]] 
 27.4003 -    real_of_int_floor_le[where r="s"]  have ss0:"?ss \<ge> 0" and ss1:"?ss < 1" 
 27.4004 -    by (auto simp add: myl[rule_format, where b="s", symmetric] myless[rule_format, where a="?ss"])
 27.4005 -  from np have n0: "real n \<ge> 0" by simp
 27.4006 -  from mult_left_mono[OF up n0] mult_strict_left_mono[OF u1 np] 
 27.4007 -  have nu0:"real n * u - s \<ge> -s" and nun:"real n * u -s < real n - s" by auto  
 27.4008 -  from int_rdvd_real[where i="i" and x="real (n::int) * u - s"] 
 27.4009 -  have "real i rdvd real n * u - s = 
 27.4010 -    (i dvd floor (real n * u -s) \<and> (real (floor (real n * u - s)) = real n * u - s ))" 
 27.4011 -    (is "_ = (?DE)" is "_ = (?D \<and> ?E)") by simp
 27.4012 -  also have "\<dots> = (?DE \<and> real(floor (real n * u - s) + floor s)\<ge> -?ss 
 27.4013 -    \<and> real(floor (real n * u - s) + floor s)< real n - ?ss)" (is "_=(?DE \<and>real ?a \<ge> _ \<and> real ?a < _)")
 27.4014 -    using nu0 nun  by auto
 27.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])
 27.4016 -  also have "\<dots> = (?DE \<and> (\<exists> j\<in> {0 .. (n - 1)}. ?a = j))" by simp
 27.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> ))"
 27.4018 -    by (simp only: ring_simps real_of_int_diff[symmetric] real_of_int_inject del: real_of_int_diff)
 27.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>"]
 27.4020 -    by (auto cong: conj_cong)
 27.4021 -  also have "\<dots> = ?rhs" by(simp cong: conj_cong) (simp add: ring_simps )
 27.4022 -  finally show ?thesis .
 27.4023 -qed
 27.4024 -
 27.4025 -definition
 27.4026 -  DVDJ:: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm"
 27.4027 -where
 27.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)"
 27.4029 -
 27.4030 -definition
 27.4031 -  NDVDJ:: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm"
 27.4032 -where
 27.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)"
 27.4034 -
 27.4035 -lemma DVDJ_DVD: 
 27.4036 -  assumes xp:"x\<ge> 0" and x1: "x < 1" and np:"real n > 0"
 27.4037 -  shows "Ifm (x#bs) (DVDJ i n s) = Ifm (x#bs) (Dvd i (CN 0 n s))"
 27.4038 -proof-
 27.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))))"
 27.4040 -  let ?s= "Inum (x#bs) s"
 27.4041 -  from foldr_disj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"]
 27.4042 -  have "Ifm (x#bs) (DVDJ i n s) = (\<exists> j\<in> {0 .. (n - 1)}. Ifm (x#bs) (?f j))" 
 27.4043 -    by (simp add: iupt_set np DVDJ_def del: iupt.simps)
 27.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])
 27.4045 -  also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] 
 27.4046 -  have "\<dots> = (real i rdvd real n * x - (-?s))" by simp
 27.4047 -  finally show ?thesis by simp
 27.4048 -qed
 27.4049 -
 27.4050 -lemma NDVDJ_NDVD: 
 27.4051 -  assumes xp:"x\<ge> 0" and x1: "x < 1" and np:"real n > 0"
 27.4052 -  shows "Ifm (x#bs) (NDVDJ i n s) = Ifm (x#bs) (NDvd i (CN 0 n s))"
 27.4053 -proof-
 27.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))))"
 27.4055 -  let ?s= "Inum (x#bs) s"
 27.4056 -  from foldr_conj_map[where xs="iupt(0,n - 1)" and bs="x#bs" and f="?f"]
 27.4057 -  have "Ifm (x#bs) (NDVDJ i n s) = (\<forall> j\<in> {0 .. (n - 1)}. Ifm (x#bs) (?f j))" 
 27.4058 -    by (simp add: iupt_set np NDVDJ_def del: iupt.simps)
 27.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])
 27.4060 -  also from rdvd01_cs[OF xp x1 np, where i="i" and s="-?s"] 
 27.4061 -  have "\<dots> = (\<not> (real i rdvd real n * x - (-?s)))" by simp
 27.4062 -  finally show ?thesis by simp
 27.4063 -qed  
 27.4064 -
 27.4065 -lemma foldr_disj_map_rlfm2: 
 27.4066 -  assumes lf: "\<forall> n . isrlfm (f n)"
 27.4067 -  shows "isrlfm (foldr disj (map f xs) F)"
 27.4068 -using lf by (induct xs, auto)
 27.4069 -lemma foldr_And_map_rlfm2: 
 27.4070 -  assumes lf: "\<forall> n . isrlfm (f n)"
 27.4071 -  shows "isrlfm (foldr conj (map f xs) T)"
 27.4072 -using lf by (induct xs, auto)
 27.4073 -
 27.4074 -lemma DVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s"
 27.4075 -  shows "isrlfm (DVDJ i n s)"
 27.4076 -proof-
 27.4077 -  let ?f="\<lambda>j. conj (Eq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j)))))
 27.4078 -                         (Dvd i (Sub (C j) (Floor (Neg s))))"
 27.4079 -  have th: "\<forall> j. isrlfm (?f j)" using nb np by auto
 27.4080 -  from DVDJ_def foldr_disj_map_rlfm2[OF th] show ?thesis by simp 
 27.4081 -qed
 27.4082 -
 27.4083 -lemma NDVDJ_l: assumes ip: "i >0" and np: "n>0" and nb: "numbound0 s"
 27.4084 -  shows "isrlfm (NDVDJ i n s)"
 27.4085 -proof-
 27.4086 -  let ?f="\<lambda>j. disj (NEq (CN 0 n (Add s (Sub (Floor (Neg s)) (C j)))))
 27.4087 -                      (NDvd i (Sub (C j) (Floor (Neg s))))"
 27.4088 -  have th: "\<forall> j. isrlfm (?f j)" using nb np by auto
 27.4089 -  from NDVDJ_def foldr_And_map_rlfm2[OF th] show ?thesis by auto
 27.4090 -qed
 27.4091 -
 27.4092 -definition DVD :: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm" where
 27.4093 -  DVD_def: "DVD i c t =
 27.4094 -  (if i=0 then eq c t else 
 27.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))"
 27.4096 -
 27.4097 -definition  NDVD :: "int \<Rightarrow> int \<Rightarrow> num \<Rightarrow> fm" where
 27.4098 -  "NDVD i c t =
 27.4099 -  (if i=0 then neq c t else 
 27.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))"
 27.4101 -
 27.4102 -lemma DVD_mono: 
 27.4103 -  assumes xp: "0\<le> x" and x1: "x < 1" 
 27.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)"
 27.4105 -  (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (DVD i n s) = ?I (Dvd i a)")
 27.4106 -proof(clarify)
 27.4107 -  fix a n s 
 27.4108 -  assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s"
 27.4109 -  let ?th = "?I (DVD i n s) = ?I (Dvd i a)"
 27.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
 27.4111 -  moreover {assume iz: "i=0" hence ?th using eq_mono[rule_format, OF conjI[OF H nb]] 
 27.4112 -      by (simp add: DVD_def rdvd_left_0_eq)}
 27.4113 -  moreover {assume inz: "i\<noteq>0" and "n=0" hence ?th by (simp add: H DVD_def) } 
 27.4114 -  moreover {assume inz: "i\<noteq>0" and "n<0" hence ?th 
 27.4115 -      by (simp add: DVD_def H DVDJ_DVD[OF xp x1] rdvd_abs1 
 27.4116 -	rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } 
 27.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)}
 27.4118 -  ultimately show ?th by blast
 27.4119 -qed
 27.4120 -
 27.4121 -lemma NDVD_mono:   assumes xp: "0\<le> x" and x1: "x < 1" 
 27.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 a)"
 27.4123 -  (is "\<forall> a n s. ?N a = ?N (CN 0 n s) \<and> _ \<longrightarrow> ?I (NDVD i n s) = ?I (NDvd i a)")
 27.4124 -proof(clarify)
 27.4125 -  fix a n s 
 27.4126 -  assume H: "?N a = ?N (CN 0 n s)" and nb: "numbound0 s"
 27.4127 -  let ?th = "?I (NDVD i n s) = ?I (NDvd i a)"
 27.4128 -  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
 27.4129 -  moreover {assume iz: "i=0" hence ?th using neq_mono[rule_format, OF conjI[OF H nb]] 
 27.4130 -      by (simp add: NDVD_def rdvd_left_0_eq)}
 27.4131 -  moreover {assume inz: "i\<noteq>0" and "n=0" hence ?th by (simp add: H NDVD_def) } 
 27.4132 -  moreover {assume inz: "i\<noteq>0" and "n<0" hence ?th 
 27.4133 -      by (simp add: NDVD_def H NDVDJ_NDVD[OF xp x1] rdvd_abs1 
 27.4134 -	rdvd_minus[where d="i" and t="real n * x + Inum (x # bs) s"]) } 
 27.4135 -  moreover {assume inz: "i\<noteq>0" and "n>0" hence ?th 
 27.4136 -      by (simp add:NDVD_def H NDVDJ_NDVD[OF xp x1] rdvd_abs1)}
 27.4137 -  ultimately show ?th by blast
 27.4138 -qed
 27.4139 -
 27.4140 -lemma DVD_l: "isrlfm (rsplit (DVD i) a)"
 27.4141 -  by (rule rsplit_l[where f="DVD i" and a="a"], auto simp add: DVD_def eq_def DVDJ_l) 
 27.4142 -(case_tac s, simp_all, case_tac "nat", simp_all)
 27.4143 -
 27.4144 -lemma NDVD_l: "isrlfm (rsplit (NDVD i) a)"
 27.4145 -  by (rule rsplit_l[where f="NDVD i" and a="a"], auto simp add: NDVD_def neq_def NDVDJ_l) 
 27.4146 -(case_tac s, simp_all, case_tac "nat", simp_all)
 27.4147 -
 27.4148 -consts rlfm :: "fm \<Rightarrow> fm"
 27.4149 -recdef rlfm "measure fmsize"
 27.4150 -  "rlfm (And p q) = conj (rlfm p) (rlfm q)"
 27.4151 -  "rlfm (Or p q) = disj (rlfm p) (rlfm q)"
 27.4152 -  "rlfm (Imp p q) = disj (rlfm (NOT p)) (rlfm q)"
 27.4153 -  "rlfm (Iff p q) = disj (conj(rlfm p) (rlfm q)) (conj(rlfm (NOT p)) (rlfm (NOT q)))"
 27.4154 -  "rlfm (Lt a) = rsplit lt a"
 27.4155 -  "rlfm (Le a) = rsplit le a"
 27.4156 -  "rlfm (Gt a) = rsplit gt a"
 27.4157 -  "rlfm (Ge a) = rsplit ge a"
 27.4158 -  "rlfm (Eq a) = rsplit eq a"
 27.4159 -  "rlfm (NEq a) = rsplit neq a"
 27.4160 -  "rlfm (Dvd i a) = rsplit (\<lambda> t. DVD i t) a"
 27.4161 -  "rlfm (NDvd i a) = rsplit (\<lambda> t. NDVD i t) a"
 27.4162 -  "rlfm (NOT (And p q)) = disj (rlfm (NOT p)) (rlfm (NOT q))"
 27.4163 -  "rlfm (NOT (Or p q)) = conj (rlfm (NOT p)) (rlfm (NOT q))"
 27.4164 -  "rlfm (NOT (Imp p q)) = conj (rlfm p) (rlfm (NOT q))"
 27.4165 -  "rlfm (NOT (Iff p q)) = disj (conj(rlfm p) (rlfm(NOT q))) (conj(rlfm(NOT p)) (rlfm q))"
 27.4166 -  "rlfm (NOT (NOT p)) = rlfm p"
 27.4167 -  "rlfm (NOT T) = F"
 27.4168 -  "rlfm (NOT F) = T"
 27.4169 -  "rlfm (NOT (Lt a)) = simpfm (rlfm (Ge a))"
 27.4170 -  "rlfm (NOT (Le a)) = simpfm (rlfm (Gt a))"
 27.4171 -  "rlfm (NOT (Gt a)) = simpfm (rlfm (Le a))"
 27.4172 -  "rlfm (NOT (Ge a)) = simpfm (rlfm (Lt a))"
 27.4173 -  "rlfm (NOT (Eq a)) = simpfm (rlfm (NEq a))"
 27.4174 -  "rlfm (NOT (NEq a)) = simpfm (rlfm (Eq a))"
 27.4175 -  "rlfm (NOT (Dvd i a)) = simpfm (rlfm (NDvd i a))"
 27.4176 -  "rlfm (NOT (NDvd i a)) = simpfm (rlfm (Dvd i a))"
 27.4177 -  "rlfm p = p" (hints simp add: fmsize_pos)
 27.4178 -
 27.4179 -lemma bound0at_l : "\<lbrakk>isatom p ; bound0 p\<rbrakk> \<Longrightarrow> isrlfm p"
 27.4180 -  by (induct p rule: isrlfm.induct, auto)
 27.4181 -lemma zgcd_le1: assumes ip: "0 < i" shows "zgcd i j \<le> i"
 27.4182 -proof-
 27.4183 -  from zgcd_zdvd1 have th: "zgcd i j dvd i" by blast
 27.4184 -  from zdvd_imp_le[OF th ip] show ?thesis .
 27.4185 -qed
 27.4186 -
 27.4187 -
 27.4188 -lemma simpfm_rl: "isrlfm p \<Longrightarrow> isrlfm (simpfm p)"
 27.4189 -proof (induct p)
 27.4190 -  case (Lt a) 
 27.4191 -  hence "bound0 (Lt a) \<or> (\<exists> c e. a = CN 0 c e \<and> c > 0 \<and> numbound0 e)"
 27.4192 -    by (cases a,simp_all, case_tac "nat", simp_all)
 27.4193 -  moreover
 27.4194 -  {assume "bound0 (Lt a)" hence bn:"bound0 (simpfm (Lt a))"  
 27.4195 -      using simpfm_bound0 by blast
 27.4196 -    have "isatom (simpfm (Lt a))" by (cases "simpnum a", auto simp add: Let_def)
 27.4197 -    with bn bound0at_l have ?case by blast}
 27.4198 -  moreover 
 27.4199 -  {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e"
 27.4200 -    {
 27.4201 -      assume cn1:"numgcd (CN 0 c (simpnum e)) \<noteq> 1" and cnz:"numgcd (CN 0 c (simpnum e)) \<noteq> 0"
 27.4202 -      with numgcd_pos[where t="CN 0 c (simpnum e)"]
 27.4203 -      have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp
 27.4204 -      from prems have th:"numgcd (CN 0 c (simpnum e)) \<le> c" 
 27.4205 -	by (simp add: numgcd_def zgcd_le1)
 27.4206 -      from prems have th': "c\<noteq>0" by auto
 27.4207 -      from prems have cp: "c \<ge> 0" by simp
 27.4208 -      from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']]
 27.4209 -	have "0 < c div numgcd (CN 0 c (simpnum e))" by simp
 27.4210 -    }
 27.4211 -    with prems have ?case
 27.4212 -      by (simp add: Let_def reducecoeff_def reducecoeffh_numbound0)}
 27.4213 -  ultimately show ?case by blast
 27.4214 -next
 27.4215 -  case (Le a)   
 27.4216 -  hence "bound0 (Le a) \<or> (\<exists> c e. a = CN 0 c e \<and> c > 0 \<and> numbound0 e)"
 27.4217 -    by (cases a,simp_all, case_tac "nat", simp_all)
 27.4218 -  moreover
 27.4219 -  {assume "bound0 (Le a)" hence bn:"bound0 (simpfm (Le a))"  
 27.4220 -      using simpfm_bound0 by blast
 27.4221 -    have "isatom (simpfm (Le a))" by (cases "simpnum a", auto simp add: Let_def)
 27.4222 -    with bn bound0at_l have ?case by blast}
 27.4223 -  moreover 
 27.4224 -  {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e"
 27.4225 -    {
 27.4226 -      assume cn1:"numgcd (CN 0 c (simpnum e)) \<noteq> 1" and cnz:"numgcd (CN 0 c (simpnum e)) \<noteq> 0"
 27.4227 -      with numgcd_pos[where t="CN 0 c (simpnum e)"]
 27.4228 -      have th1:"numgcd (CN 0 c (simpnum e)) > 0" by simp
 27.4229 -      from prems have th:"numgcd (CN 0 c (simpnum e)) \<le> c" 
 27.4230 -	by (simp add: numgcd_def zgcd_le1)
 27.4231 -      from prems have th': "c\<noteq>0" by auto
 27.4232 -      from prems have cp: "c \<ge> 0" by simp
 27.4233 -      from zdiv_mono2[OF cp th1 th, simplified zdiv_self[OF th']]
 27.4234 -	have "0 < c div numgcd (CN 0 c (simpnum e))" by simp
 27.4235 -    }
 27.4236 -    with prems have ?case
 27.4237 -      by (simp add: Let_def reducecoeff_def simpnum_numbound0 reducecoeffh_numbound0)}
 27.4238 -  ultimately show ?case by blast
 27.4239 -next
 27.4240 -  case (Gt a)   
 27.4241 -  hence "bound0 (Gt a) \<or> (\<exists> c e. a = CN 0 c e \<and> c > 0 \<and> numbound0 e)"
 27.4242 -    by (cases a,simp_all, case_tac "nat", simp_all)
 27.4243 -  moreover
 27.4244 -  {assume "bound0 (Gt a)" hence bn:"bound0 (simpfm (Gt a))"  
 27.4245 -      using simpfm_bound0 by blast
 27.4246 -    have "isatom (simpfm (Gt a))" by (cases "simpnum a", auto simp add: Let_def)
 27.4247 -    with bn bound0at_l have ?case by blast}
 27.4248 -  moreover 
 27.4249 -  {fix c e assume "a = CN 0 c e" and "c>0" and "numbound0 e"
 27.4250 -    {
 27.4251 -      assume cn1:"numgcd (C