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