src/HOL/Library/Sum_Of_Squares.thy
author wenzelm
Thu, 06 Aug 2009 19:51:59 +0200
changeset 32332 bc5cec7b2be6
parent 32268 378ebd64447d
child 32333 d4cb904cc63c
permissions -rw-r--r--
misc changes to SOS by Philipp Meyer:
CSDP_EXE as central setting;
separate component src/HOL/Library/Sum_Of_Squares;
misc tuning and rearrangement of neos_csdp_client;
more robust treatment of shell paths;
debugging depends on local flag;
removed unused parts;
     1 (* Title:      Library/Sum_Of_Squares
     2    Author:     Amine Chaieb, University of Cambridge
     3 
     4 In order to use the method sos, call it with (sos remote_csdp) to use the remote solver
     5 or install CSDP (https://projects.coin-or.org/Csdp/), set the Isabelle environment
     6 variable CSDP_EXE and call it with (sos csdp). By default, sos calls remote_csdp.
     7 This can take of the order of a minute for one sos call, because sos calls CSDP repeatedly.
     8 If you install CSDP locally, sos calls typically takes only a few seconds.
     9 
    10 *)
    11 
    12 header {* A decision method for universal multivariate real arithmetic with addition, 
    13           multiplication and ordering using semidefinite programming*}
    14 
    15 theory Sum_Of_Squares
    16 imports Complex_Main (* "~~/src/HOL/Decision_Procs/Dense_Linear_Order" *)
    17 uses
    18   ("positivstellensatz.ML")
    19   ("Sum_Of_Squares/sum_of_squares.ML")
    20   ("Sum_Of_Squares/sos_wrapper.ML")
    21 begin
    22 
    23 (* setup sos tactic *)
    24 
    25 use "positivstellensatz.ML"
    26 use "Sum_Of_Squares/sum_of_squares.ML"
    27 use "Sum_Of_Squares/sos_wrapper.ML"
    28 
    29 setup SosWrapper.setup
    30 
    31 text{* Tests -- commented since they work only when csdp is installed  or take too long with remote csdps *}
    32 
    33 (*
    34 lemma "(3::real) * x + 7 * a < 4 & 3 < 2 * x \<Longrightarrow> a < 0" by sos
    35 
    36 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
    37 
    38 lemma "(3::real) * x + 7 * a < 4 & 3 < 2 * x --> a < 0" by sos
    39 
    40 lemma "(0::real) <= x & x <= 1 & 0 <= y & y <= 1  --> x^2 + y^2 < 1 |(x - 1)^2 + y^2 < 1 | x^2 + (y - 1)^2 < 1 | (x - 1)^2 + (y - 1)^2 < 1" by sos
    41 
    42 lemma "(0::real) <= x & 0 <= y & 0 <= z & x + y + z <= 3 --> x * y + x * z + y * z >= 3 * x * y * z" by sos
    43 
    44 lemma "((x::real)^2 + y^2 + z^2 = 1) --> (x + y + z)^2 <= 3" by sos
    45 
    46 lemma "(w^2 + x^2 + y^2 + z^2 = 1) --> (w + x + y + z)^2 <= (4::real)" by sos
    47 
    48 lemma "(x::real) >= 1 & y >= 1 --> x * y >= x + y - 1" by sos
    49 
    50 lemma "(x::real) > 1 & y > 1 --> x * y > x + y - 1" by sos; 
    51 
    52 lemma "abs(x) <= 1 --> abs(64 * x^7 - 112 * x^5 + 56 * x^3 - 7 * x) <= (1::real)" by sos  
    53 *)
    54 (* ------------------------------------------------------------------------- *)
    55 (* One component of denominator in dodecahedral example.                     *)
    56 (* ------------------------------------------------------------------------- *)
    57 (*
    58 lemma "2 <= x & x <= 125841 / 50000 & 2 <= y & y <= 125841 / 50000 & 2 <= z & z <= 125841 / 50000 --> 2 * (x * z + x * y + y * z) - (x * x + y * y + z * z) >= (0::real)" by sos;
    59 *)
    60 (* ------------------------------------------------------------------------- *)
    61 (* Over a larger but simpler interval.                                       *)
    62 (* ------------------------------------------------------------------------- *)
    63 (*
    64 lemma "(2::real) <= x & x <= 4 & 2 <= y & y <= 4 & 2 <= z & z <= 4 --> 0 <= 2 * (x * z + x * y + y * z) - (x * x + y * y + z * z)" by sos
    65 *)
    66 (* ------------------------------------------------------------------------- *)
    67 (* We can do 12. I think 12 is a sharp bound; see PP's certificate.          *)
    68 (* ------------------------------------------------------------------------- *)
    69 (*
    70 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
    71 *)
    72 
    73 (* ------------------------------------------------------------------------- *)
    74 (* Inequality from sci.math (see "Leon-Sotelo, por favor").                  *)
    75 (* ------------------------------------------------------------------------- *)
    76 (*
    77 lemma "0 <= (x::real) & 0 <= y & (x * y = 1) --> x + y <= x^2 + y^2" by sos 
    78 
    79 lemma "0 <= (x::real) & 0 <= y & (x * y = 1) --> x * y * (x + y) <= x^2 + y^2" by sos 
    80 
    81 lemma "0 <= (x::real) & 0 <= y --> x * y * (x + y)^2 <= (x^2 + y^2)^2" by sos
    82 
    83 lemma "(0::real) <= a & 0 <= b & 0 <= c & c * (2 * a + b)^3/ 27 <= x \<longrightarrow> c * a^2 * b <= x" by sos
    84  
    85 lemma "(0::real) < x --> 0 < 1 + x + x^2" by sos
    86 
    87 lemma "(0::real) <= x --> 0 < 1 + x + x^2" by sos
    88 
    89 lemma "(0::real) < 1 + x^2" by sos
    90 
    91 lemma "(0::real) <= 1 + 2 * x + x^2" by sos
    92 
    93 lemma "(0::real) < 1 + abs x" by sos
    94 
    95 lemma "(0::real) < 1 + (1 + x)^2 * (abs x)" by sos
    96 
    97 
    98 
    99 lemma "abs ((1::real) + x^2) = (1::real) + x^2" by sos
   100 lemma "(3::real) * x + 7 * a < 4 \<and> 3 < 2 * x \<longrightarrow> a < 0" by sos
   101 
   102 lemma "(0::real) < x --> 1 < y --> y * x <= z --> x < z" by sos
   103 lemma "(1::real) < x --> x^2 < y --> 1 < y" by sos
   104 lemma "(b::real)^2 < 4 * a * c --> ~(a * x^2 + b * x + c = 0)" by sos
   105 lemma "(b::real)^2 < 4 * a * c --> ~(a * x^2 + b * x + c = 0)" by sos
   106 lemma "((a::real) * x^2 + b * x + c = 0) --> b^2 >= 4 * a * c" by sos
   107 lemma "(0::real) <= b & 0 <= c & 0 <= x & 0 <= y & (x^2 = c) & (y^2 = a^2 * c + b) --> a * c <= y * x" by sos
   108 lemma "abs(x - z) <= e & abs(y - z) <= e & 0 <= u & 0 <= v & (u + v = 1) --> abs((u * x + v * y) - z) <= (e::real)" by sos
   109 *)
   110 (*
   111 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?*)
   112 (*
   113 lemma "(0::real) <= x --> (1 + x + x^2)/(1 + x^2) <= 1 + x"
   114 apply sos
   115 done
   116 
   117 lemma "(0::real) <= x --> 1 - x <= 1 / (1 + x + x^2)"
   118 apply sos
   119 done
   120 
   121 lemma "(x::real) <= 1 / 2 --> - x - 2 * x^2 <= - x / (1 - x)"
   122 apply sos
   123 done 
   124 
   125 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
   126 *)
   127 
   128 end
   129