source: CIVL/examples/experimental/positiveDefinitive.cvl

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * In linear algebra, a symmetric n × n real matrix M is said to be positive definite
3 * if z^{T}Mz is positive for every non-zero column vector z of n real numbers.
4 * Here z^{T} denotes the transpose of z.
5 * SARL can't prove the query: 0<X0[1]^2+X0[0]^2
6 * under the contex: exists i : int . ((0 < -1*i+2) && (0 <= i) && (0 != X0[i]))
7 *
8*/
9
10#include<civlc.cvh>
11
12$input int n=2;
13$input double z[n];
14double M[n][n];
15$assume(n>0);
16$input double k;
17// z is a non-zero column vector
18//$assume($exists {int i | 0 <=i && i<n} z[i] != 0);
19$assume($forall {double x|x!=0} x*x > 0);
20
21// use Identity matrix for a test here
22void initialize(){
23 for(int i=0; i<n; i++){
24 for(int j=0; j<n; j++){
25 if(i==j)
26 M[i][j]=1;
27 else
28 M[i][j]=0;
29 }
30 }
31}
32
33double compute(){
34 double zTxM[n], result=0;
35 _Bool assumption=$false;
36
37 for(int i=0; i<n; i++){
38 zTxM[i]=0;
39 assumption=assumption || (z[i]!=0);
40 for(int j=0; j<n; j++){
41 // checks that M is symmetric
42 $assert(M[i][j]==M[j][i]);
43 zTxM[i]+=z[i]*M[i][j];
44 }
45 }
46 $assume(assumption);
47 for(int i=0; i<n; i++){
48 result+=zTxM[i]*z[i];
49 }
50 $assert(result>0);
51 return result;
52}
53
54int main(){
55 $assume(k!=0);
56 $assert(k*k>=0);
57 initialize();
58 compute();
59}
Note: See TracBrowser for help on using the repository browser.