src/HOL/Real/Ferrante_Rackoff.thy
author haftmann
Thu May 10 22:11:37 2007 +0200 (2007-05-10)
changeset 22929 e6b6f8dd03e9
parent 22917 3c56b12fd946
child 23319 173f4d2dedc2
permissions -rw-r--r--
cleaned up
wenzelm@19640
     1
(*
wenzelm@19640
     2
    ID:         $Id$
wenzelm@19640
     3
    Author:     Amine Chaieb, TU Muenchen
huffman@20634
     4
*)
wenzelm@19640
     5
huffman@20634
     6
header {* Ferrante and Rackoff Algorithm: LCF-proof-synthesis version. *}
wenzelm@19640
     7
wenzelm@19640
     8
theory Ferrante_Rackoff
wenzelm@19640
     9
imports RealPow
wenzelm@19640
    10
uses ("ferrante_rackoff_proof.ML") ("ferrante_rackoff.ML")
wenzelm@19640
    11
begin
wenzelm@19640
    12
wenzelm@19640
    13
  (* Synthesis of \<exists>z. \<forall>x<z. P x = P1 *)
wenzelm@19640
    14
lemma minf: 
wenzelm@19640
    15
  "\<exists>(z::real) . \<forall>x<z. x < t = True "  "\<exists>(z::real) . \<forall>x<z. x > t = False "
wenzelm@19640
    16
  "\<exists>(z::real) . \<forall>x<z. x \<le> t = True "  "\<exists>(z::real) . \<forall>x<z. x \<ge> t = False "
wenzelm@19640
    17
  "\<exists>(z::real) . \<forall>x<z. (x = t) = False "  "\<exists>(z::real) . \<forall>x<z. (x \<noteq> t) = True "
wenzelm@19640
    18
  "\<exists>z. \<forall>(x::real)<z. (P::bool) = P"
wenzelm@19640
    19
  "\<lbrakk>\<exists>(z1::real). \<forall>x<z1. P1 x = P1'; \<exists>z2. \<forall>x<z2. P2 x = P2'\<rbrakk> \<Longrightarrow>
wenzelm@19640
    20
  \<exists>z. \<forall>x<z. (P1 x \<and> P2 x) = (P1' \<and> P2')"
wenzelm@19640
    21
  "\<lbrakk>\<exists>(z1::real). \<forall>x<z1. P1 x = P1'; \<exists>z2. \<forall>x<z2. P2 x = P2'\<rbrakk> \<Longrightarrow>
wenzelm@19640
    22
  \<exists>z. \<forall>x<z. (P1 x \<or> P2 x) = (P1' \<or> P2')"
wenzelm@19640
    23
  by (rule_tac x="t" in exI,simp)+
wenzelm@19640
    24
(clarsimp,rule_tac x="min z1 z2" in exI,simp)+
wenzelm@19640
    25
wenzelm@19640
    26
lemma minf_ex: "\<lbrakk>\<exists>z. \<forall>x<z. P (x::real) = P1 ; P1\<rbrakk> \<Longrightarrow> \<exists> x. P x"
wenzelm@19640
    27
  by clarsimp (rule_tac x="z - 1" in exI, auto)
wenzelm@19640
    28
wenzelm@19640
    29
  (* Synthesis of \<exists>z. \<forall>x>z. P x = P1 *)
wenzelm@19640
    30
lemma pinf: 
wenzelm@19640
    31
  "\<exists>(z::real) . \<forall>x>z. x < t = False "  "\<exists>(z::real) . \<forall>x>z. x > t = True "
wenzelm@19640
    32
  "\<exists>(z::real) . \<forall>x>z. x \<le> t = False "  "\<exists>(z::real) . \<forall>x>z. x \<ge> t = True "
wenzelm@19640
    33
  "\<exists>(z::real) . \<forall>x>z. (x = t) = False "  "\<exists>(z::real) . \<forall>x>z. (x \<noteq> t) = True "
wenzelm@19640
    34
  "\<exists>z. \<forall>(x::real)>z. (P::bool) = P"
wenzelm@19640
    35
  "\<lbrakk>\<exists>(z1::real). \<forall>x>z1. P1 x = P1'; \<exists>z2. \<forall>x>z2. P2 x = P2'\<rbrakk> \<Longrightarrow>
wenzelm@19640
    36
  \<exists>z. \<forall>x>z. (P1 x \<and> P2 x) = (P1' \<and> P2')"
wenzelm@19640
    37
  "\<lbrakk>\<exists>(z1::real). \<forall>x>z1. P1 x = P1'; \<exists>z2. \<forall>x>z2. P2 x = P2'\<rbrakk> \<Longrightarrow>
wenzelm@19640
    38
  \<exists>z. \<forall>x>z. (P1 x \<or> P2 x) = (P1' \<or> P2')"
wenzelm@19640
    39
  by (rule_tac x="t" in exI,simp)+
wenzelm@19640
    40
(clarsimp,rule_tac x="max z1 z2" in exI,simp)+
wenzelm@19640
    41
wenzelm@19640
    42
lemma pinf_ex: "\<lbrakk>\<exists>z. \<forall>x>z. P (x::real) = P1 ; P1\<rbrakk> \<Longrightarrow> \<exists> x. P x"
wenzelm@19640
    43
  by clarsimp (rule_tac x="z+1" in exI, auto)
wenzelm@19640
    44
wenzelm@19640
    45
    (* The ~P1 \<and> ~P2 \<and> P x \<longrightarrow> \<exists> u,u' \<in> U. u \<le> x \<le> u'*)
wenzelm@19640
    46
lemma nmilbnd: 
wenzelm@19640
    47
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> (x::real) < t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    48
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> (x::real) > t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    49
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> (x::real) \<le> t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    50
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and> (x::real) \<ge> t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    51
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  (x::real) = t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    52
  "t \<in> U \<Longrightarrow>\<forall>x. \<not>True \<and> (x::real) \<noteq> t \<longrightarrow>  (\<exists> u\<in> U. u \<le> x )"
wenzelm@19640
    53
  "\<forall> (x::real). ~P \<and> P \<longrightarrow>  (\<exists> u\<in> U. u \<le> x )"
wenzelm@19640
    54
  "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 (x::real) \<longrightarrow>  (\<exists> u\<in> U. u \<le> x) ; 
wenzelm@19640
    55
  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x )\<rbrakk> \<Longrightarrow> 
wenzelm@19640
    56
  \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    57
  "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 (x::real) \<longrightarrow>  (\<exists> u\<in> U. u \<le> x) ; 
wenzelm@19640
    58
  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<le> x )\<rbrakk> \<Longrightarrow> 
wenzelm@19640
    59
  \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
    60
  by auto (rule_tac x="t" in bexI,simp,simp)
wenzelm@19640
    61
wenzelm@19640
    62
lemma npiubnd: 
wenzelm@19640
    63
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  (x::real) < t \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    64
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> (x::real) > t \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    65
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  (x::real) \<le> t \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    66
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> (x::real) \<ge> t \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    67
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>False \<and>  (x::real) = t \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    68
  "t \<in> U \<Longrightarrow> \<forall>x. \<not>True \<and> (x::real) \<noteq> t \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x )"
wenzelm@19640
    69
  "\<forall> (x::real). ~P \<and> P \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x )"
wenzelm@19640
    70
  "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 (x::real) \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x) ;  \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x )\<rbrakk> 
wenzelm@19640
    71
  \<Longrightarrow>  \<forall>x. \<not>(P1' \<and> P2') \<and> (P1 x \<and> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    72
  "\<lbrakk>\<forall>x. \<not>P1' \<and> P1 (x::real) \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x) ; \<forall>x. \<not>P2' \<and> P2 x \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x )\<rbrakk> 
wenzelm@19640
    73
  \<Longrightarrow> \<forall>x. \<not>(P1' \<or> P2') \<and> (P1 x \<or> P2 x) \<longrightarrow>  (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
    74
  by auto (rule_tac x="t" in bexI,simp,simp)
wenzelm@19640
    75
lemma npmibnd: "\<lbrakk>\<forall>x. \<not> MP \<and> P (x::real) \<longrightarrow> (\<exists> u\<in> U. u \<le> x); \<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<ge> x)\<rbrakk> 
wenzelm@19640
    76
  \<Longrightarrow> \<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<le> x \<and> x \<le> u')"
wenzelm@19640
    77
by auto
wenzelm@19640
    78
wenzelm@19640
    79
  (* Synthesis of  (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x<u \<and> P x \<and> l < y < u \<longrightarrow> P y*)
wenzelm@19640
    80
lemma lin_dense_lt: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (x::real) < t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y< t)"
wenzelm@19640
    81
proof(clarsimp)
wenzelm@19640
    82
  fix x l u y  assume tU: "t \<in> U" and noU: "\<forall>t\<Colon>real. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" 
wenzelm@19640
    83
    and xu: "x<u"  and px: "x < t" and ly: "l<y" and yu:"y < u"
wenzelm@19640
    84
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@19640
    85
  {assume H: "y> t" hence "l < t \<and> t < u" using px lx yu by simp 
wenzelm@19640
    86
    with tU noU have "False" by auto} hence "\<not> y>t"  by auto hence "y \<le> t" by auto
wenzelm@19640
    87
  thus "y < t" using tny by simp 
wenzelm@19640
    88
qed
wenzelm@19640
    89
    
wenzelm@19640
    90
lemma lin_dense_gt: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (x::real) > t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y> t)"
wenzelm@19640
    91
proof(clarsimp)
wenzelm@19640
    92
  fix x l u y
wenzelm@19640
    93
  assume tU: "t \<in> U" and noU: "\<forall>t\<Colon>real. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
wenzelm@19640
    94
  and px: "x > t" and ly: "l<y" and yu:"y < u"
wenzelm@19640
    95
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@19640
    96
  {assume H: "y< t" hence "l < t \<and> t < u" using px xu ly by simp 
wenzelm@19640
    97
    with tU noU have "False" by auto}
wenzelm@19640
    98
  hence	"\<not> y<t"  by auto hence "y \<ge> t" by auto
wenzelm@19640
    99
  thus "y > t" using tny by simp 
wenzelm@19640
   100
qed
wenzelm@19640
   101
lemma lin_dense_le: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (x::real) \<le> t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<le> t)"
wenzelm@19640
   102
proof(clarsimp)
wenzelm@19640
   103
  fix x l u y
wenzelm@19640
   104
  assume tU: "t \<in> U" and noU: "\<forall>t\<Colon>real. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
wenzelm@19640
   105
  and px: "x \<le> t" and ly: "l<y" and yu:"y < u"
wenzelm@19640
   106
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@19640
   107
  {assume H: "y> t" hence "l < t \<and> t < u" using px lx yu by simp 
wenzelm@19640
   108
    with tU noU have "False" by auto}
wenzelm@19640
   109
  hence	"\<not> y>t"  by auto thus "y \<le> t" by auto
wenzelm@19640
   110
qed
wenzelm@19640
   111
    
wenzelm@19640
   112
lemma lin_dense_ge: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (x::real) \<ge> t \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<ge> t)"
wenzelm@19640
   113
proof(clarsimp)
wenzelm@19640
   114
  fix x l u y
wenzelm@19640
   115
  assume tU: "t \<in> U" and noU: "\<forall>t\<Colon>real. l < t \<and> t < u \<longrightarrow> t \<notin> U" and lx: "l < x" and xu: "x<u"
wenzelm@19640
   116
  and px: "x \<ge> t" and ly: "l<y" and yu:"y < u"
wenzelm@19640
   117
  from tU noU ly yu have tny: "t\<noteq>y" by auto
wenzelm@19640
   118
  {assume H: "y< t" hence "l < t \<and> t < u" using px xu ly by simp 
wenzelm@19640
   119
    with tU noU have "False" by auto}
wenzelm@19640
   120
  hence	"\<not> y<t"  by auto thus "y \<ge> t" by auto
wenzelm@19640
   121
qed
wenzelm@19640
   122
lemma lin_dense_eq: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (x::real) = t   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y= t)"  by auto
wenzelm@19640
   123
lemma lin_dense_neq: "t \<in> U \<Longrightarrow> \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (x::real) \<noteq> t   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> y\<noteq> t)"  by auto
wenzelm@19640
   124
lemma lin_dense_fm: "\<forall>(x::real) l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P)"  by auto
wenzelm@19640
   125
wenzelm@19640
   126
lemma lin_dense_conj: 
wenzelm@19640
   127
  "\<lbrakk>\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P1 (x::real) 
wenzelm@19640
   128
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P1 y) ;  
wenzelm@19640
   129
  \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P2 (x::real) 
wenzelm@19640
   130
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow> 
wenzelm@19640
   131
  \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (P1 x \<and> P2 x) 
wenzelm@19640
   132
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> (P1 y \<and> P2 y))"
wenzelm@19640
   133
  by blast
wenzelm@19640
   134
lemma lin_dense_disj: 
wenzelm@19640
   135
  "\<lbrakk>\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P1 (x::real) 
wenzelm@19640
   136
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P1 y) ;  
wenzelm@19640
   137
  \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P2 (x::real) 
wenzelm@19640
   138
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P2 y)\<rbrakk> \<Longrightarrow> 
wenzelm@19640
   139
  \<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> (P1 x \<or> P2 x) 
wenzelm@19640
   140
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> (P1 y \<or> P2 y))"
wenzelm@19640
   141
  by blast
wenzelm@19640
   142
wenzelm@19640
   143
lemma finite_set_intervals:
wenzelm@19640
   144
  assumes px: "P (x::real)" and lx: "l \<le> x" and xu: "x \<le> u" and linS: "l\<in> S" 
wenzelm@19640
   145
  and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
wenzelm@19640
   146
  shows "\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a \<le> x \<and> x \<le> b \<and> P x"
wenzelm@19640
   147
proof-
wenzelm@19640
   148
  let ?Mx = "{y. y\<in> S \<and> y \<le> x}"
wenzelm@19640
   149
  let ?xM = "{y. y\<in> S \<and> x \<le> y}"
wenzelm@19640
   150
  let ?a = "Max ?Mx"
wenzelm@19640
   151
  let ?b = "Min ?xM"
wenzelm@19640
   152
  have MxS: "?Mx \<subseteq> S" by blast
wenzelm@19640
   153
  hence fMx: "finite ?Mx" using fS finite_subset by auto
wenzelm@19640
   154
  from lx linS have linMx: "l \<in> ?Mx" by blast
wenzelm@19640
   155
  hence Mxne: "?Mx \<noteq> {}" by blast
wenzelm@19640
   156
  have xMS: "?xM \<subseteq> S" by blast
wenzelm@19640
   157
  hence fxM: "finite ?xM" using fS finite_subset by auto
wenzelm@19640
   158
  from xu uinS have linxM: "u \<in> ?xM" by blast
wenzelm@19640
   159
  hence xMne: "?xM \<noteq> {}" by blast
haftmann@22917
   160
  have ax: "?a \<le> x" using Mxne fMx by auto
haftmann@22917
   161
  have xb: "x \<le> ?b" using xMne fxM by auto
haftmann@22917
   162
  have "?a \<in> ?Mx" using Max_in [OF fMx Mxne] by simp
haftmann@22917
   163
  hence ainS: "?a \<in> S" using MxS by blast
haftmann@22917
   164
  have "?b \<in> ?xM" using Min_in [OF fxM xMne] by simp
haftmann@22917
   165
  hence binS: "?b \<in> S" using xMS by blast
wenzelm@19640
   166
  have noy:"\<forall> y. ?a < y \<and> y < ?b \<longrightarrow> y \<notin> S"
wenzelm@19640
   167
  proof(clarsimp)
wenzelm@19640
   168
    fix y   assume ay: "?a < y" and yb: "y < ?b" and yS: "y \<in> S"
wenzelm@19640
   169
    from yS have "y\<in> ?Mx \<or> y\<in> ?xM" by auto
haftmann@22917
   170
    moreover {assume "y \<in> ?Mx" hence "y \<le> ?a" using Mxne fMx by auto
haftmann@22917
   171
    with ay have "False" by simp}
haftmann@22917
   172
    moreover {assume "y \<in> ?xM" hence "y \<ge> ?b" using xMne fxM by auto
haftmann@22917
   173
    with yb have "False" by simp}
wenzelm@19640
   174
    ultimately show "False" by blast
wenzelm@19640
   175
  qed
wenzelm@19640
   176
  from ainS binS noy ax xb px show ?thesis by blast
wenzelm@19640
   177
qed
wenzelm@19640
   178
wenzelm@19640
   179
lemma finite_set_intervals2:
wenzelm@19640
   180
  assumes px: "P (x::real)" and lx: "l \<le> x" and xu: "x \<le> u" and linS: "l\<in> S" 
wenzelm@19640
   181
  and uinS: "u \<in> S" and fS:"finite S" and lS: "\<forall> x\<in> S. l \<le> x" and Su: "\<forall> x\<in> S. x \<le> u"
wenzelm@19640
   182
  shows "(\<exists> s\<in> S. P s) \<or> (\<exists> a \<in> S. \<exists> b \<in> S. (\<forall> y. a < y \<and> y < b \<longrightarrow> y \<notin> S) \<and> a < x \<and> x < b \<and> P x)"
wenzelm@19640
   183
proof-
wenzelm@19640
   184
  from finite_set_intervals[where P="P", OF px lx xu linS uinS fS lS Su]
wenzelm@19640
   185
  obtain a and b where 
wenzelm@19640
   186
    as: "a\<in> S" and bs: "b\<in> S" and noS:"\<forall>y. a < y \<and> y < b \<longrightarrow> y \<notin> S" 
wenzelm@19640
   187
    and axb: "a \<le> x \<and> x \<le> b \<and> P x"  by auto
wenzelm@19640
   188
  from axb have "x= a \<or> x= b \<or> (a < x \<and> x < b)" by auto
wenzelm@19640
   189
  thus ?thesis using px as bs noS by blast 
wenzelm@19640
   190
qed
wenzelm@19640
   191
wenzelm@19640
   192
lemma rinf_U:
wenzelm@19640
   193
  assumes fU: "finite U" 
wenzelm@19640
   194
  and lin_dense: "\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P x 
wenzelm@19640
   195
  \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P y )"
wenzelm@19640
   196
  and nmpiU: "\<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<le> x \<and> x \<le> u')"
wenzelm@19640
   197
  and nmi: "\<not> MP"  and npi: "\<not> PP"  and ex: "\<exists> x.  P (x::real)"
wenzelm@19640
   198
  shows "\<exists> u\<in> U. \<exists> u' \<in> U. P ((u + u') / 2)" 
wenzelm@19640
   199
proof-
wenzelm@19640
   200
  from ex obtain x where px: "P x" by blast
wenzelm@19640
   201
  from px nmi npi nmpiU have "\<exists> u\<in> U. \<exists> u' \<in> U. u \<le> x \<and> x \<le> u'" by auto
wenzelm@19640
   202
  then obtain u and u' where uU:"u\<in> U" and uU': "u' \<in> U" and ux:"u \<le> x" and xu':"x \<le> u'" by auto 
wenzelm@19640
   203
  from uU have Une: "U \<noteq> {}" by auto
wenzelm@19640
   204
  let ?l = "Min U"
wenzelm@19640
   205
  let ?u = "Max U"
wenzelm@19640
   206
  have linM: "?l \<in> U" using fU Une by simp
wenzelm@19640
   207
  have uinM: "?u \<in> U" using fU Une by simp
wenzelm@19640
   208
  have lM: "\<forall> t\<in> U. ?l \<le> t" using Une fU by auto
wenzelm@19640
   209
  have Mu: "\<forall> t\<in> U. t \<le> ?u" using Une fU by auto
wenzelm@19640
   210
  have "?l \<le> u" using uU Une lM by auto hence lx: "?l \<le> x" using ux by simp
wenzelm@19640
   211
  have "u' \<le> ?u" using uU' Une Mu by simp hence xu: "x \<le> ?u" using xu' by simp
wenzelm@19640
   212
  from finite_set_intervals2[where P="P",OF px lx xu linM uinM fU lM Mu]
wenzelm@19640
   213
  have "(\<exists> s\<in> U. P s) \<or> 
wenzelm@19640
   214
      (\<exists> t1\<in> U. \<exists> t2 \<in> U. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> U) \<and> t1 < x \<and> x < t2 \<and> P x)" .
wenzelm@19640
   215
  moreover { fix u assume um: "u\<in>U" and pu: "P u"
wenzelm@19640
   216
    have "(u + u) / 2 = u" by auto 
wenzelm@19640
   217
    with um pu have "P ((u + u) / 2)" by simp
wenzelm@19640
   218
    with um have ?thesis by blast}
wenzelm@19640
   219
  moreover{
wenzelm@19640
   220
    assume "\<exists> t1\<in> U. \<exists> t2 \<in> U. (\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> U) \<and> t1 < x \<and> x < t2 \<and> P x"
wenzelm@19640
   221
      then obtain t1 and t2 where t1M: "t1 \<in> U" and t2M: "t2\<in> U" 
wenzelm@19640
   222
	and noM: "\<forall> y. t1 < y \<and> y < t2 \<longrightarrow> y \<notin> U" and t1x: "t1 < x" and xt2: "x < t2" and px: "P x"
wenzelm@19640
   223
	by blast
wenzelm@19640
   224
      from t1x xt2 have t1t2: "t1 < t2" by simp
wenzelm@19640
   225
      let ?u = "(t1 + t2) / 2"
wenzelm@19640
   226
      from less_half_sum[OF t1t2] gt_half_sum[OF t1t2] have t1lu: "t1 < ?u" and ut2: "?u < t2" by auto
wenzelm@19640
   227
      from lin_dense[rule_format, OF] noM t1x xt2 px t1lu ut2 have "P ?u" by blast
wenzelm@19640
   228
      with t1M t2M have ?thesis by blast}
wenzelm@19640
   229
    ultimately show ?thesis by blast
wenzelm@19640
   230
  qed
wenzelm@19640
   231
wenzelm@19640
   232
theorem fr_eq: 
wenzelm@19640
   233
  assumes fU: "finite U"
wenzelm@19640
   234
  and lin_dense: "\<forall>x l u. (\<forall> t. l < t \<and> t< u \<longrightarrow> t \<notin> U) \<and> l< x \<and> x < u \<and> P x 
wenzelm@19640
   235
   \<longrightarrow> (\<forall> y. l < y \<and> y < u \<longrightarrow> P y )"
wenzelm@19640
   236
  and nmibnd: "\<forall>x. \<not> MP \<and> P (x::real) \<longrightarrow> (\<exists> u\<in> U. u \<le> x)"
wenzelm@19640
   237
  and npibnd: "\<forall>x. \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. u \<ge> x)"
wenzelm@19640
   238
  and mi: "\<exists>z. \<forall>x<z. P x = MP"  and pi: "\<exists>z. \<forall>x>z. P x = PP"
wenzelm@19640
   239
  shows "(\<exists> x. P (x::real)) = (MP \<or> PP \<or> (\<exists> u \<in> U. \<exists> u'\<in> U. P ((u + u') / 2)))" 
wenzelm@19640
   240
  (is "_ = (_ \<or> _ \<or> ?F)" is "?E = ?D")
wenzelm@19640
   241
proof
wenzelm@19640
   242
  assume px: "\<exists> x. P x"
wenzelm@19640
   243
  have "MP \<or> PP \<or> (\<not> MP \<and> \<not> PP)" by blast
wenzelm@19640
   244
  moreover {assume "MP \<or> PP" hence "?D" by blast}
wenzelm@19640
   245
  moreover {assume nmi: "\<not> MP" and npi: "\<not> PP"
wenzelm@19640
   246
    from npmibnd[OF nmibnd npibnd] 
wenzelm@19640
   247
    have nmpiU: "\<forall>x. \<not> MP \<and> \<not>PP \<and> P x \<longrightarrow> (\<exists> u\<in> U. \<exists> u' \<in> U. u \<le> x \<and> x \<le> u')" .
wenzelm@19640
   248
    from rinf_U[OF fU lin_dense nmpiU nmi npi px] have "?D" by blast}   
wenzelm@19640
   249
  ultimately show "?D" by blast
wenzelm@19640
   250
next
wenzelm@19640
   251
  assume "?D" 
wenzelm@19640
   252
  moreover {assume m:"MP" from minf_ex[OF mi m] have "?E" .}
wenzelm@19640
   253
  moreover {assume p: "PP" from pinf_ex[OF pi p] have "?E" . }
wenzelm@19640
   254
  moreover {assume f:"?F" hence "?E" by blast}
wenzelm@19640
   255
  ultimately show "?E" by blast
wenzelm@19640
   256
qed
wenzelm@19640
   257
wenzelm@19640
   258
lemma fr_simps: 
wenzelm@19640
   259
  "(True | P) = True"  "(P | True) = True"  "(True & P) = P"  "(P & True) = P"
wenzelm@19640
   260
  "(P & P) = P"  "(P & (P & P')) = (P & P')"  "(P & (P | P')) = P"  "(False | P) = P"
wenzelm@19640
   261
  "(P | False) = P"  "(False & P) = False"  "(P & False) = False"  "(P | P) = P"
wenzelm@19640
   262
  "(P | (P | P')) = (P | P')"  "(P | (P & P')) = P"  "(~ True) = False"  "(~ False) = True"
wenzelm@19640
   263
  "(x::real) \<le> x"  "(\<exists> u\<in> {}. Q u) = False"
wenzelm@19640
   264
  "(\<exists> u\<in> (insert (x::real) U). \<exists>u'\<in> (insert x U). R ((u+u') / 2)) = 
wenzelm@19640
   265
  ((R x) \<or> (\<exists>u\<in>U. R((x+u) / 2))\<or> (\<exists> u\<in> U. \<exists> u'\<in> U. R ((u + u') /2)))"
wenzelm@19640
   266
  "(\<exists> u\<in> (insert (x::real) U). R u) = (R x \<or> (\<exists> u\<in> U. R u))"
wenzelm@19640
   267
  "Q' (((t::real) + t)/2) = Q' t"
wenzelm@19640
   268
by (auto simp add: add_ac)
wenzelm@19640
   269
  
wenzelm@19640
   270
lemma fr_prepqelim:
wenzelm@19640
   271
  "(\<exists> x. True) = True" "(\<exists> x. False) = False" "(ALL x. A x) = (~ (EX x. ~ (A x)))"
wenzelm@19640
   272
  "(P \<longrightarrow> Q) = ((\<not> P) \<or> Q)" "(\<not> (P \<longrightarrow> Q)) = (P \<and> (\<not> Q))" "(\<not> (P = Q)) = ((\<not> P) = Q)" 
wenzelm@19640
   273
  "(\<not> (P \<and> Q)) = ((\<not> P) \<or> (\<not> Q))" "(\<not> (P \<or> Q)) = ((\<not> P) \<and> (\<not> Q))"
wenzelm@19640
   274
by auto
wenzelm@19640
   275
  (* Lemmas for the normalization of Expressions *)
wenzelm@19640
   276
lemma nadd_cong:  
wenzelm@19640
   277
  assumes m: "m'*m = l" and n: "n'*n = (l::real)"
wenzelm@19640
   278
  and mz: "m \<noteq> 0" and nz: "n \<noteq> 0" and lz: "l \<noteq> 0"
wenzelm@19640
   279
  and ad: "(m'*t + n'*s) = t'"
wenzelm@19640
   280
  shows "t/m + s/n = (t' / l)"
wenzelm@19640
   281
proof-
wenzelm@19640
   282
  from lz m n have mz': "m'\<noteq>0" and nz':"n' \<noteq> 0" by auto
wenzelm@19640
   283
  have "t' / l = (m'*t + n'*s) / l" using ad by simp
wenzelm@19640
   284
  also have "\<dots> = (m'*t) / l + (n'*s) / l" by (simp add: add_divide_distrib)
wenzelm@19640
   285
  also have "\<dots> = (m'*t) /(m'*m) + (n'*s) /(n'*n)" using m n by simp
wenzelm@19640
   286
  also have "\<dots> = t/m + s/n" using mz nz mz' nz' by simp
wenzelm@19640
   287
  finally show ?thesis  by simp
wenzelm@19640
   288
qed
wenzelm@19640
   289
wenzelm@19640
   290
lemma nadd_cong_same: "\<lbrakk> (n::real) = m ; t+s = t'\<rbrakk> \<Longrightarrow> t/n + s/m = t'/n"  
wenzelm@19640
   291
  by (simp add: add_divide_distrib[symmetric])
wenzelm@19640
   292
lemma plus_cong: "\<lbrakk>t = t'; s = s'; t' + s' = r\<rbrakk> \<Longrightarrow> t+s = r"
wenzelm@19640
   293
  by simp
wenzelm@19640
   294
lemma diff_cong: "\<lbrakk>t = t'; s = s'; t' - s' = r\<rbrakk> \<Longrightarrow> t-s = r"
wenzelm@19640
   295
  by simp
wenzelm@19640
   296
lemma mult_cong2: "\<lbrakk>(t ::real) = t'; c*t' = r\<rbrakk> \<Longrightarrow> t*c = r"
wenzelm@19640
   297
  by (simp add: mult_ac)
wenzelm@19640
   298
lemma mult_cong: "\<lbrakk>(t ::real) = t'; c*t' = r\<rbrakk> \<Longrightarrow> c*t = r"
wenzelm@19640
   299
  by simp
wenzelm@19640
   300
lemma divide_cong: "\<lbrakk> (t::real) = t' ; t'/n = r\<rbrakk> \<Longrightarrow> t/n = r"
wenzelm@19640
   301
  by simp
wenzelm@19640
   302
lemma naddh_cong_ts: "\<lbrakk>t1 + (s::real) = t'\<rbrakk> \<Longrightarrow> (x + t1) + s = x + t'" by simp
wenzelm@19640
   303
lemma naddh_cong_st: "\<lbrakk>(t::real) + s = t'\<rbrakk> \<Longrightarrow> t+ (x + s) = x + t'" by simp
wenzelm@19640
   304
lemma naddh_cong_same: "\<lbrakk>(c1::real) + c2 = c ; t1 + t2 = t\<rbrakk> \<Longrightarrow> (c1*x + t1) + (c2*x+t2) = c*x + t"
wenzelm@19640
   305
  by (simp add: ring_eq_simps,simp only: ring_distrib(2)[symmetric])
wenzelm@19640
   306
lemma naddh_cong_same0: "\<lbrakk>(c1::real) + c2 = 0 ; t1 + t2 = t\<rbrakk> \<Longrightarrow> (c1*x + t1) + (c2*x+t2) = t"
wenzelm@19640
   307
  by (simp add: ring_eq_simps,simp only: ring_distrib(2)[symmetric]) simp
wenzelm@19640
   308
lemma ncmul_congh: "\<lbrakk> c*c' = (k::real) ; c*t = t'\<rbrakk>  \<Longrightarrow> c*(c'*x + t) = k*x + t'"
wenzelm@19640
   309
  by (simp add: ring_eq_simps)
wenzelm@19640
   310
lemma ncmul_cong: "\<lbrakk> c / n = c'/n' ; c'*t = (t'::real)\<rbrakk> \<Longrightarrow> c* (t/n) = t'/n'"
wenzelm@19640
   311
proof-
wenzelm@19640
   312
  assume "c / n = c'/n'" and "c'*t = (t'::real)"
wenzelm@19640
   313
  have "\<lbrakk> c' / n' = c/n ; (t'::real) = c'*t\<rbrakk> \<Longrightarrow> c* (t/n) = t'/n'"
wenzelm@19640
   314
    by (simp add: divide_inverse ring_eq_simps)  thus ?thesis using prems by simp
wenzelm@19640
   315
qed
wenzelm@19640
   316
wenzelm@19640
   317
lemma nneg_cong: "(-1 ::real)*t = t' \<Longrightarrow> - t = t'"  by simp
wenzelm@19640
   318
lemma uminus_cong: "\<lbrakk> t = t' ; - t' = r\<rbrakk> \<Longrightarrow>  - t = r"  by simp
wenzelm@19640
   319
lemma nsub_cong: "\<lbrakk>- (s::real) = s'; t + s' = t'\<rbrakk> \<Longrightarrow> t - s = t'"  by simp
wenzelm@19640
   320
lemma ndivide_cong: "m*n = (m'::real) \<Longrightarrow> (t/m) / n = t / m'"  by simp
wenzelm@19640
   321
lemma normalizeh_var: "(x::real) = (1*x + 0) / 1"  by simp
wenzelm@19640
   322
lemma nrefl: "(x::real) = x/1"  by simp
wenzelm@19640
   323
wenzelm@19640
   324
    (* cong rules for atoms normalization *)
wenzelm@19640
   325
  (* the < -case *)
wenzelm@19640
   326
lemma normalize_ltxpos_cong: assumes smt: "s - t = (c*x+r) / (n::real)"
wenzelm@19640
   327
  and cnp: "n/c > 0" and rr': "r/c + r'/c' = 0"
wenzelm@19640
   328
  shows "(s < t) = (x < r'/c')"
wenzelm@19640
   329
proof-
wenzelm@19640
   330
  from cnp have cnz: "c \<noteq> 0" by auto
wenzelm@19640
   331
  from cnp have nnz: "n\<noteq>0" by auto
wenzelm@19640
   332
  from rr' have rr'': "-(r/c) = r'/c'" by simp
wenzelm@19640
   333
  have "s < t = (s - t < 0)" by simp
wenzelm@19640
   334
  also have "\<dots> = ((c*x+r) / n < 0)" using smt by simp
wenzelm@19640
   335
  also have "\<dots> = ((c/n)*x + r/n < 0)" by (simp add: add_divide_distrib)
wenzelm@19640
   336
  also have "\<dots> = ( (n/c)*((c/n)*x + r/n) < (n/c)*0)" 
wenzelm@19640
   337
    using cnp mult_less_cancel_left[where c="(n/c)" and b="0"] by simp 
wenzelm@19640
   338
  also have "\<dots> = (x + r/c < 0)" 
wenzelm@19640
   339
    using cnz nnz by (simp add: add_divide_distrib ring_eq_simps)
wenzelm@19640
   340
  also have "\<dots> = (x < - (r/c))" by auto
wenzelm@19640
   341
  finally show ?thesis using rr'' by simp
wenzelm@19640
   342
qed
wenzelm@19640
   343
wenzelm@19640
   344
lemma normalize_ltxneg_cong: assumes smt: "s - t = (c*x+r) / (n::real)"
wenzelm@19640
   345
  and cnp: "n/c < 0" and rr': "r/c + r'/c' = 0"
wenzelm@19640
   346
  shows "(s < t) = (x > r'/c')"
wenzelm@19640
   347
proof-
wenzelm@19640
   348
  from cnp have cnz: "c \<noteq> 0" by auto
wenzelm@19640
   349
  from cnp have nnz: "n\<noteq>0" by auto
wenzelm@19640
   350
  from cnp have cnp': "\<not> (n/c > 0)" by simp
wenzelm@19640
   351
  from rr' have rr'': "-(r/c) = r'/c'" by simp
wenzelm@19640
   352
  have "s < t = (s - t < 0)" by simp
wenzelm@19640
   353
  also have "\<dots> = ((c*x+r) / n < 0)" using smt by simp
wenzelm@19640
   354
  also have "\<dots> = ((c/n)*x + r/n < 0)" by (simp add: add_divide_distrib)
wenzelm@19640
   355
  also have "\<dots> = ( (n/c)*((c/n)*x + r/n) > 0)"
wenzelm@19640
   356
    using zero_less_mult_iff[where a="n/c" and b="(c/n)*x + r/n", simplified cnp cnp' simp_thms]
wenzelm@19640
   357
    by simp 
wenzelm@19640
   358
  also have "\<dots> = (x + r/c > 0)" 
wenzelm@19640
   359
    using cnz nnz by (simp add: add_divide_distrib ring_eq_simps)
wenzelm@19640
   360
  also have "\<dots> = (x > - (r/c))" by auto
wenzelm@19640
   361
  finally show ?thesis using rr'' by simp
wenzelm@19640
   362
qed
wenzelm@19640
   363
lemma normalize_ltground_cong: "\<lbrakk> s -t = (r::real) ; r < 0 = P\<rbrakk> \<Longrightarrow> s < t = P"  by auto
wenzelm@19640
   364
lemma normalize_ltnoxpos_cong: 
wenzelm@19640
   365
  assumes st: "s - t = (r::real) / n" and mp: "n > 0"
wenzelm@19640
   366
  shows "s < t = (r <0)"
wenzelm@19640
   367
proof-  
wenzelm@19640
   368
  have "s < t = (s - t < 0)" by simp
wenzelm@19640
   369
  also have "\<dots> = (r / n < 0)" using st by simp
wenzelm@19640
   370
  also have "\<dots> = (n* (r/n) < 0)" using mult_less_0_iff[where a="n" and b="r/n"] mp by simp
wenzelm@19640
   371
  finally show ?thesis using mp by auto
wenzelm@19640
   372
qed
wenzelm@19640
   373
wenzelm@19640
   374
lemma normalize_ltnoxneg_cong: 
wenzelm@19640
   375
  assumes st: "s - t = (r::real) / n" and mp: "n < 0"
wenzelm@19640
   376
  shows "s < t = (r > 0)"
wenzelm@19640
   377
proof-  
wenzelm@19640
   378
  have "s < t = (s - t < 0)" by simp
wenzelm@19640
   379
  also have "\<dots> = (r / n < 0)" using st by simp
wenzelm@19640
   380
  also have "\<dots> = (n* (r/n) > 0)" using zero_less_mult_iff[where a="n" and b="r/n"] mp by simp
wenzelm@19640
   381
  finally show ?thesis using mp by auto
wenzelm@19640
   382
qed
wenzelm@19640
   383
wenzelm@19640
   384
  (* the <= -case *)
wenzelm@19640
   385
lemma normalize_lexpos_cong: assumes smt: "s - t = (c*x+r) / (n::real)"
wenzelm@19640
   386
  and cnp: "n/c > 0" and rr': "r/c + r'/c' = 0"
wenzelm@19640
   387
  shows "(s \<le> t) = (x \<le> r'/c')"
wenzelm@19640
   388
proof-
wenzelm@19640
   389
  from cnp have cnz: "c \<noteq> 0" by auto
wenzelm@19640
   390
  from cnp have nnz: "n\<noteq>0" by auto
wenzelm@19640
   391
  from rr' have rr'': "-(r/c) = r'/c'" by simp
wenzelm@19640
   392
  have "s \<le> t = (s - t \<le> 0)" by simp
wenzelm@19640
   393
  also have "\<dots> = ((c*x+r) / n \<le> 0)" using smt by simp
wenzelm@19640
   394
  also have "\<dots> = ((c/n)*x + r/n \<le> 0)" by (simp add: add_divide_distrib)
wenzelm@19640
   395
  also have "\<dots> = ( (n/c)*((c/n)*x + r/n) \<le> (n/c)*0)" 
wenzelm@19640
   396
    using cnp mult_le_cancel_left[where c="(n/c)" and b="0"] by simp 
wenzelm@19640
   397
  also have "\<dots> = (x + r/c \<le> 0)" 
wenzelm@19640
   398
    using cnz nnz by (simp add: add_divide_distrib ring_eq_simps)
wenzelm@19640
   399
  also have "\<dots> = (x \<le> - (r/c))" by auto
wenzelm@19640
   400
  finally show ?thesis using rr'' by simp
wenzelm@19640
   401
qed
wenzelm@19640
   402
wenzelm@19640
   403
lemma normalize_lexneg_cong: assumes smt: "s - t = (c*x+r) / (n::real)"
wenzelm@19640
   404
  and cnp: "n/c < 0" and rr': "r/c + r'/c' = 0"
wenzelm@19640
   405
  shows "(s \<le> t) = (x \<ge> r'/c')"
wenzelm@19640
   406
proof-
wenzelm@19640
   407
  from cnp have cnz: "c \<noteq> 0" by auto
wenzelm@19640
   408
  from cnp have nnz: "n\<noteq>0" by auto
wenzelm@19640
   409
  from cnp have cnp': "\<not> (n/c \<ge> 0) \<and> n/c \<le> 0" by simp
wenzelm@19640
   410
  from rr' have rr'': "-(r/c) = r'/c'" by simp
wenzelm@19640
   411
  have "s \<le> t = (s - t \<le> 0)" by simp
wenzelm@19640
   412
  also have "\<dots> = ((c*x+r) / n \<le> 0)" using smt by simp
wenzelm@19640
   413
  also have "\<dots> = ((c/n)*x + r/n \<le> 0)" by (simp add: add_divide_distrib)
wenzelm@19640
   414
  also have "\<dots> = ( (n/c)*((c/n)*x + r/n) \<ge> 0)"
wenzelm@19640
   415
    using zero_le_mult_iff[where a="n/c" and b="(c/n)*x + r/n", simplified cnp' simp_thms]
wenzelm@19640
   416
    by simp 
wenzelm@19640
   417
  also have "\<dots> = (x + r/c \<ge> 0)" 
wenzelm@19640
   418
    using cnz nnz by (simp add: add_divide_distrib ring_eq_simps)
wenzelm@19640
   419
  also have "\<dots> = (x \<ge> - (r/c))" by auto
wenzelm@19640
   420
  finally show ?thesis using rr'' by simp
wenzelm@19640
   421
qed
wenzelm@19640
   422
lemma normalize_leground_cong: "\<lbrakk> s -t = (r::real) ; r \<le> 0 = P\<rbrakk> \<Longrightarrow> s \<le> t = P"  by auto
wenzelm@19640
   423
lemma normalize_lenoxpos_cong: 
wenzelm@19640
   424
  assumes st: "s - t = (r::real) / n" and mp: "n > 0"
wenzelm@19640
   425
  shows "s \<le> t = (r \<le>0)"
wenzelm@19640
   426
proof-  
wenzelm@19640
   427
  have "s \<le> t = (s - t \<le> 0)" by simp
wenzelm@19640
   428
  also have "\<dots> = (r / n \<le> 0)" using st by simp
wenzelm@19640
   429
  also have "\<dots> = (n* (r/n) \<le> 0)" using mult_le_0_iff[where a="n" and b="r/n"] mp by simp
wenzelm@19640
   430
  finally show ?thesis using mp by auto
wenzelm@19640
   431
qed
wenzelm@19640
   432
wenzelm@19640
   433
lemma normalize_lenoxneg_cong: 
wenzelm@19640
   434
  assumes st: "s - t = (r::real) / n" and mp: "n < 0"
wenzelm@19640
   435
  shows "s \<le> t = (r \<ge> 0)"
wenzelm@19640
   436
proof-  
wenzelm@19640
   437
  have "s \<le> t = (s - t \<le> 0)" by simp
wenzelm@19640
   438
  also have "\<dots> = (r / n \<le> 0)" using st by simp
wenzelm@19640
   439
  also have "\<dots> = (n* (r/n) \<ge> 0)" using zero_le_mult_iff[where a="n" and b="r/n"] mp by simp
wenzelm@19640
   440
  finally show ?thesis using mp by auto
wenzelm@19640
   441
qed
wenzelm@19640
   442
    (* The = -case *)
wenzelm@19640
   443
wenzelm@19640
   444
lemma normalize_eqxpos_cong: assumes smt: "s - t = (c*x+r) / (n::real)"
wenzelm@19640
   445
  and cp: "c > 0" and nnz: "n \<noteq> 0" and rr': "r+ r' = 0"
wenzelm@19640
   446
  shows "(s = t) = (x = r'/c)"
wenzelm@19640
   447
proof-
wenzelm@19640
   448
  from rr' have rr'': "-r = r'" by simp
wenzelm@19640
   449
  have "(s = t) = (s - t = 0)" by simp
wenzelm@19640
   450
  also have "\<dots> = ((c*x + r) /n = 0)" using smt by simp
wenzelm@19640
   451
  also have "\<dots> = (c*x = -r)" using nnz by auto
wenzelm@19640
   452
  also have "\<dots> = (x = (-r) / c)" using cp eq_divide_eq[where c="c" and a="x" and b="-r"]
wenzelm@19640
   453
    by (simp add: mult_ac)
wenzelm@19640
   454
  finally show ?thesis using rr'' by simp
wenzelm@19640
   455
qed
wenzelm@19640
   456
wenzelm@19640
   457
lemma normalize_eqxneg_cong: assumes smt: "s - t = (c*x+r) / (n::real)"
wenzelm@19640
   458
  and cp: "c < 0" and nnz: "n \<noteq> 0" and cc': "c+ c' = 0"
wenzelm@19640
   459
  shows "(s = t) = (x = r/c')"
wenzelm@19640
   460
proof-
wenzelm@19640
   461
  from cc' have cc'': "-c = c'" by simp
wenzelm@19640
   462
  have "(s = t) = (s - t = 0)" by simp
wenzelm@19640
   463
  also have "\<dots> = ((c*x + r) /n = 0)" using smt by simp
wenzelm@19640
   464
  also have "\<dots> = ((-c)*x = r)" using nnz by auto
wenzelm@19640
   465
  also have "\<dots> = (x = r / (-c))" using cp eq_divide_eq[where c="-c" and a="x" and b="r"]
wenzelm@19640
   466
    by (simp add: mult_ac)
wenzelm@19640
   467
  finally show ?thesis using cc'' by simp
wenzelm@19640
   468
qed
wenzelm@19640
   469
wenzelm@19640
   470
lemma normalize_eqnox_cong: "\<lbrakk>s - t = (r::real) / n;n \<noteq> 0\<rbrakk> \<Longrightarrow> s = t = (r = 0)" by auto
wenzelm@19640
   471
wenzelm@19640
   472
lemma normalize_eqground_cong: "\<lbrakk>s - t =(r::real)/n;n \<noteq> 0;(r = 0) = P \<rbrakk> \<Longrightarrow> s=t = P" by auto
wenzelm@19640
   473
wenzelm@19640
   474
lemma trivial_sum_of_opposites: "-t = t' \<Longrightarrow> t + t' = (0::real)" by simp
wenzelm@19640
   475
lemma sum_of_opposite_denoms: 
wenzelm@19640
   476
  assumes cc': "(c::real) + c' = 0" shows "r/c + r/c' = 0"
wenzelm@19640
   477
proof-
wenzelm@19640
   478
  from cc' have "c' = -c" by simp
wenzelm@19640
   479
  thus ?thesis by simp
wenzelm@19640
   480
qed
wenzelm@19640
   481
lemma sum_of_same_denoms: " -r = (r'::real) \<Longrightarrow> r/c + r'/c = 0"  by auto
wenzelm@19640
   482
lemma normalize_not_lt: "t \<le> (s::real) = P \<Longrightarrow> (\<not> s<t) = P"  by auto
wenzelm@19640
   483
lemma normalize_not_le: "t < (s::real) = P \<Longrightarrow> (\<not> s\<le>t) = P"  by auto
wenzelm@19640
   484
lemma normalize_not_eq: "\<lbrakk> t = (s::real) = P ; (~P) = P' \<rbrakk> \<Longrightarrow> (s\<noteq>t) = P'"  by auto
wenzelm@19640
   485
lemma ex_eq_cong: "(!! x. A x = B x) \<Longrightarrow> ((\<exists>x. A x) = (\<exists> x. B x))"  by blast
wenzelm@19640
   486
wenzelm@19640
   487
use "ferrante_rackoff_proof.ML"
wenzelm@19640
   488
use "ferrante_rackoff.ML"
wenzelm@19640
   489
setup "Ferrante_Rackoff.setup"
wenzelm@19640
   490
wenzelm@19640
   491
end