src/HOL/Library/Sum_Of_Squares.thy
changeset 31131 d9752181691a
parent 31119 2532bb2d65c7
child 31512 27118561c2e0
     1.1 --- a/src/HOL/Library/Sum_Of_Squares.thy	Tue May 12 21:39:19 2009 +0200
     1.2 +++ b/src/HOL/Library/Sum_Of_Squares.thy	Wed May 13 17:13:33 2009 +0100
     1.3 @@ -9,30 +9,20 @@
     1.4    uses "positivstellensatz.ML" "sum_of_squares.ML"
     1.5    begin
     1.6  
     1.7 -method_setup sos = {* 
     1.8 -let 
     1.9 - fun strip_all ct = 
    1.10 -  case term_of ct of 
    1.11 -   Const("all",_) $ Abs (xn,xT,p) => 
    1.12 -    let val (a,(v,t')) = (apsnd (Thm.dest_abs (SOME xn)) o Thm.dest_comb) ct
    1.13 -    in apfst (cons v) (strip_all t')
    1.14 -    end
    1.15 - | _ => ([],ct)
    1.16 +(* Note: 
    1.17 +
    1.18 +In order to use the method sos, install CSDP (https://projects.coin-or.org/Csdp/) and put the executable csdp on your path. 
    1.19 +
    1.20 +*)
    1.21  
    1.22 - fun core_sos_conv ctxt t = Drule.arg_cong_rule @{cterm Trueprop} (Sos.real_sos ctxt (Thm.dest_arg t) RS @{thm Eq_TrueI})
    1.23 - fun core_sos_tac ctxt = CSUBGOAL (fn (ct, i) => 
    1.24 -   let val (avs, p) = strip_all ct
    1.25 -       val th = standard (fold_rev forall_intr avs (Sos.real_sos ctxt (Thm.dest_arg p)))
    1.26 -   in rtac th i end) (* CONVERSION o core_sos_conv *)
    1.27 -in Scan.succeed (SIMPLE_METHOD' o core_sos_tac)
    1.28 -end
    1.29  
    1.30 -*} "Prove universal problems over the reals using sums of squares"
    1.31 +method_setup sos = {* Scan.succeed (SIMPLE_METHOD' o Sos.sos_tac) *} 
    1.32 +  "Prove universal problems over the reals using sums of squares"
    1.33  
    1.34 -text{* Tests -- commented since they work only when csdp is installed *}
    1.35 +text{* Tests -- commented since they work only when csdp is installed -- see above *}
    1.36  
    1.37  (*
    1.38 -lemma "(3::real) * x + 7 * a < 4 & 3 < 2 * x --> a < 0" by sos
    1.39 +lemma "(3::real) * x + 7 * a < 4 & 3 < 2 * x \<Longrightarrow> a < 0" by sos
    1.40  
    1.41  lemma "a1 >= 0 & a2 >= 0 \<and> (a1 * a1 + a2 * a2 = b1 * b1 + b2 * b2 + 2) \<and> (a1 * b1 + a2 * b2 = 0) --> a1 * a2 - b1 * b2 >= (0::real)" by sos
    1.42  
    1.43 @@ -69,8 +59,8 @@
    1.44  (* ------------------------------------------------------------------------- *)
    1.45  (*
    1.46  lemma "2 <= (x::real) & x <= 4 & 2 <= y & y <= 4 & 2 <= z & z <= 4 --> 12 <= 2 * (x * z + x * y + y * z) - (x * x + y * y + z * z)" by sos
    1.47 +
    1.48  *)
    1.49 -
    1.50  (* ------------------------------------------------------------------------- *)
    1.51  (* Inequality from sci.math (see "Leon-Sotelo, por favor").                  *)
    1.52  (* ------------------------------------------------------------------------- *)
    1.53 @@ -110,5 +100,20 @@
    1.54  *)
    1.55  (*
    1.56  lemma "((x::real) - y - 2 * x^4 = 0) & 0 <= x & x <= 2 & 0 <= y & y <= 3 --> y^2 - 7 * y - 12 * x + 17 >= 0" by sos *) (* Too hard?*)
    1.57 +(*
    1.58 +lemma "(0::real) <= x --> (1 + x + x^2)/(1 + x^2) <= 1 + x"
    1.59 +apply sos
    1.60 +done
    1.61 +
    1.62 +lemma "(0::real) <= x --> 1 - x <= 1 / (1 + x + x^2)"
    1.63 +apply sos
    1.64 +done
    1.65 +
    1.66 +lemma "(x::real) <= 1 / 2 --> - x - 2 * x^2 <= - x / (1 - x)"
    1.67 +apply sos
    1.68 +done 
    1.69 +
    1.70 +lemma "4*r^2 = p^2 - 4*q & r >= (0::real) & x^2 + p*x + q = 0 --> 2*(x::real) = - p + 2*r | 2*x = -p - 2*r" by sos
    1.71 +*)
    1.72  
    1.73  end