[sdpb] 143/233: Separated SDPB.m from examples

Tobias Hansen thansen at moszumanska.debian.org
Thu Mar 9 04:06:31 UTC 2017


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository sdpb.

commit f5b7223741841f9ef13c1141f22834c774ec1081
Author: David Simmons-Duffin <dsd at athena.sns.ias.edu>
Date:   Mon Feb 2 01:23:04 2015 -0500

    Separated SDPB.m from examples
---
 mathematica/BootstrapExample.m | 108 ++++++++++++++++++++++++++++++
 mathematica/SDPB.m             | 147 -----------------------------------------
 mathematica/Tests.m            |  44 ++++++++++++
 3 files changed, 152 insertions(+), 147 deletions(-)

diff --git a/mathematica/BootstrapExample.m b/mathematica/BootstrapExample.m
new file mode 100644
index 0000000..bd092cd
--- /dev/null
+++ b/mathematica/BootstrapExample.m
@@ -0,0 +1,108 @@
+(* Examples *)
+
+<<"SDPB.m";
+
+(* 2d Bootstrap Example *)
+
+tableDir="/data/dsd/sdpa-multicorrelators/tables-zzb-singlespin";
+spacetimeDim=3;
+
+prec=200;
+
+error[msg_] := (Print[msg]; Exit[];);
+
+floatToString[x_]:=If[Abs[x]<10^(-10),"0", ToString[CForm[SetAccuracy[x,10]]]];
+
+(* Fail with an error message if a file doesn't exist *)
+safeGet[file_] := If[FileExistsQ[file], Get[file], error[file <> " does not exist. Exiting."];];
+
+(* Fail with an error message if a file doesn't exist *)
+safeImport[file_] := If[FileExistsQ[file], Import[file], error[file <> " does not exist. Exiting."];];
+
+(* Memoize rcDerivPolTable so we don't fetch files multiple times *)
+(* This is the old basic table with thresholds instead of keptPoleOrder *)
+rcDerivPolTable[nmax_] := (
+    rcDerivPolTable[nmax] = safeGet[
+        $HomeDirectory<>"/Dropbox/SDP3D/rho-expansion/rcDerivTable-nmax"<>ToString[nmax]<>"-thresh10E-2-order60-shifting-allL.m"]);
+
+(* These are the newer tables with keptPoleOrder *)
+derivPolTable[d_, delta12_, delta34_, L_, nmax_, keptPoleOrder_, order_] :=
+    safeImport[
+        StringJoin[
+            tableDir,
+            "/nmax",            ToString[nmax],
+            "/zzbDerivTable-d", ToString[N[d]],
+            "-delta12-",        floatToString[delta12],
+            "-delta34-",        floatToString[delta34],
+            "-L",               ToString[L],
+            "-nmax",            ToString[nmax],
+            "-keptPoleOrder",   ToString[keptPoleOrder],
+            "-order",           ToString[order], 
+            ".mx"]];
+
+(* Computation Setup *)
+
+seriesDataToRules[ruleName_,series_] := Module[
+    {toRule},
+    toRule[expr_,{m_,n_}] := ruleName[m-1,n-1]->(m-1)!(n-1)!expr;
+    toRule[expr_,_]       := expr;
+    Flatten[MapIndexed[toRule,Normal[series],2]]
+];
+
+(* Here we use that z and zb are symmetric *)
+withDeltaPhiToWithoutDeltaPhi[DeltaPhi_][mMax_,nMax_] := Module[
+    {series, half},
+    half = SetPrecision[1/2,prec];
+    series = Series[
+        ((1-z) (1-zb))^DeltaPhi f[z,zb]/.{z->half+dz,zb->half+dzb},
+    {dz,0,mMax},
+    {dzb,0,nMax}
+    ] // Normal;
+seriesDataToRules[withDeltaPhiDeriv,
+    CoefficientList[series,{dz,dzb}]/.{
+        Derivative[j_,k_][f][_,_]:>zzbDeriv[Max[j,k],Min[j,k]],
+        f[_,_]:>zzbDeriv[0,0]
+                                      }
+    ]
+];
+
+leadingCoefficient[pols_,x_]:=Coefficient[pols,x^Max[Exponent[pols,x]]];
+
+oddDerivs[nMax_]  := Flatten[Table[withDeltaPhiDeriv[n+i-1,n-i]/((n+i-1)!(n-i)!),{n,1,nMax},{i,1,n}]];
+evenDerivs[nMax_] := Flatten[Table[withDeltaPhiDeriv[n+i-2,n-i]/((n+i-2)!(n-i)!),{n,1,nMax},{i,1,n}]];
+
+singletSpectrumDisallowed[datFile_][deltaSigLowPrec_,deltaEpsLowPrec_,nmax_,Lmax_] := Module[
+    {
+        coeffs,unitOp,norm,obj,
+        DeltaScalarShift=SetPrecision[deltaEpsLowPrec-1,prec],
+        DeltaPhi=SetPrecision[deltaSigLowPrec,prec],
+        addDeltaPhi,
+        pols
+    },
+
+    addDeltaPhi=withDeltaPhiToWithoutDeltaPhi[DeltaPhi][2nmax,2nmax];
+
+    (* FIXME! *)
+    pols=Table[
+        PositiveMatrixWithPrefactor[DampedRational[1,{},rho,x], {{
+            Expand[
+                Expand[
+                    Expand[
+                        oddDerivs[nmax]/.addDeltaPhi
+                          ]/.zzbToRcTable[nmax]
+                      ]/.rcDerivPolTable[nmax][[L+1]]
+                  ]
+         }}],
+        {L,0,Lmax,2}
+    ];
+
+    unitOp=oddDerivs[nmax]/.addDeltaPhi/.{
+        zzbDeriv[0,0]->1,
+        zzbDeriv[_,_]->0
+    };
+
+    pols = MapAt[#/.x->x+DeltaScalarShift&,pols,1];
+    norm = unitOp;
+    obj = 0*unitOp;
+    WriteBootstrapSDP[datFile,SDP[obj,norm,pols]];
+];
diff --git a/mathematica/SDPB.m b/mathematica/SDPB.m
index 3e36e83..a25a094 100644
--- a/mathematica/SDPB.m
+++ b/mathematica/SDPB.m
@@ -131,150 +131,3 @@ WriteBootstrapSDP[file_, SDP[objective_, normalization_, positiveMatricesWithPre
 
     Close[stream];
 ];
-
-(*Test Computations*)
-
-(* Maximize {a,b}.{0,-1} = -b over {a,b} such that {a,b}.{1,0}=a=1 and 
-
-E^(-x)(a(1+x^4) + b(x^4/12 + x^2)) >= 0 for all x>=0
-
-Equivalently,
-
-1+x^4 + b(x^4/12 + x^2) >= 0 for all x >= 0
-
-The prefactor DampedRational[1,{},1/E,x] doesn't affect the answer,
-but does affect the choice of sample scalings and bilinear basis.
-
-*)
-testSDP[datFile_] := Module[
-    {
-        pols = {PositiveMatrixWithPrefactor[DampedRational[1,{}, 1/E,x], {{{1 + x^4, x^4/12 + x^2}}}]},
-        norm = {1, 0},
-        obj  = {0, -1}
-    },
-
-    WriteBootstrapSDP[datFile, SDP[obj, norm, pols]];];
-
-(* A similar computation to the above, except with nontrivial matrix semidefiniteness constraints *)
-testSDPMatrix[datFile_] := Module[
-    {
-        pols = {
-            PositiveMatrixWithPrefactor[
-                DampedRational[1, {}, 1/E, x],
-                {{{1 + x^4, 1 + x^4/12 + x^2}, {x^2,     x/5}},
-                 {{x^2,     x/5},              {2 + x^4, x^4/3 + 2*x^2}}}],
-            PositiveMatrixWithPrefactor[
-                DampedRational[1, {}, 1/E, x],
-                {{{1 + 3x^4/4, 1 + x^4/12 + x^2}, {x^2,     1/2 + x/5}},
-                 {{x^2,     1/2 + x/5},        {2 + 3x^4/5, x^4/3 + 2*x^2}}}]
-        },
-        norm = {1, 0},
-        obj  = {0, -1}
-    },
-
-    WriteBootstrapSDP[datFile, SDP[obj, norm, pols]];];
-
-(*2d Bootstrap Example*)
-
-tableDir="/data/dsd/sdpa-multicorrelators/tables-zzb-singlespin";
-spacetimeDim=3;
-
-prec=200;
-
-error[msg_] := (Print[msg]; Exit[];);
-
-floatToString[x_]:=If[Abs[x]<10^(-10),"0", ToString[CForm[SetAccuracy[x,10]]]];
-
-(* Fail with an error message if a file doesn't exist *)
-safeGet[file_] := If[FileExistsQ[file], Get[file], error[file <> " does not exist. Exiting."];];
-
-(* Fail with an error message if a file doesn't exist *)
-safeImport[file_] := If[FileExistsQ[file], Import[file], error[file <> " does not exist. Exiting."];];
-
-(* Memoize rcDerivPolTable so we don't fetch files multiple times *)
-(* This is the old basic table with thresholds instead of keptPoleOrder *)
-rcDerivPolTable[nmax_] := (
-    rcDerivPolTable[nmax] = safeGet[
-        $HomeDirectory<>"/Dropbox/SDP3D/rho-expansion/rcDerivTable-nmax"<>ToString[nmax]<>"-thresh10E-2-order60-shifting-allL.m"]);
-
-(* These are the newer tables with keptPoleOrder *)
-derivPolTable[d_, delta12_, delta34_, L_, nmax_, keptPoleOrder_, order_] :=
-    safeImport[
-        StringJoin[
-            tableDir,
-            "/nmax",            ToString[nmax],
-            "/zzbDerivTable-d", ToString[N[d]],
-            "-delta12-",        floatToString[delta12],
-            "-delta34-",        floatToString[delta34],
-            "-L",               ToString[L],
-            "-nmax",            ToString[nmax],
-            "-keptPoleOrder",   ToString[keptPoleOrder],
-            "-order",           ToString[order], 
-            ".mx"]];
-
-(* Computation Setup *)
-
-seriesDataToRules[ruleName_,series_] := Module[
-    {toRule},
-    toRule[expr_,{m_,n_}] := ruleName[m-1,n-1]->(m-1)!(n-1)!expr;
-    toRule[expr_,_]       := expr;
-    Flatten[MapIndexed[toRule,Normal[series],2]]
-];
-
-(* Here we use that z and zb are symmetric *)
-withDeltaPhiToWithoutDeltaPhi[DeltaPhi_][mMax_,nMax_] := Module[
-    {series, half},
-    half = SetPrecision[1/2,prec];
-    series = Series[
-        ((1-z) (1-zb))^DeltaPhi f[z,zb]/.{z->half+dz,zb->half+dzb},
-    {dz,0,mMax},
-    {dzb,0,nMax}
-    ] // Normal;
-seriesDataToRules[withDeltaPhiDeriv,
-    CoefficientList[series,{dz,dzb}]/.{
-        Derivative[j_,k_][f][_,_]:>zzbDeriv[Max[j,k],Min[j,k]],
-        f[_,_]:>zzbDeriv[0,0]
-                                      }
-    ]
-];
-
-leadingCoefficient[pols_,x_]:=Coefficient[pols,x^Max[Exponent[pols,x]]];
-
-oddDerivs[nMax_]  := Flatten[Table[withDeltaPhiDeriv[n+i-1,n-i]/((n+i-1)!(n-i)!),{n,1,nMax},{i,1,n}]];
-evenDerivs[nMax_] := Flatten[Table[withDeltaPhiDeriv[n+i-2,n-i]/((n+i-2)!(n-i)!),{n,1,nMax},{i,1,n}]];
-
-singletSpectrumDisallowed[datFile_][deltaSigLowPrec_,deltaEpsLowPrec_,nmax_,Lmax_] := Module[
-    {
-        coeffs,unitOp,norm,obj,
-        DeltaScalarShift=SetPrecision[deltaEpsLowPrec-1,prec],
-        DeltaPhi=SetPrecision[deltaSigLowPrec,prec],
-        addDeltaPhi,
-        pols
-    },
-
-    addDeltaPhi=withDeltaPhiToWithoutDeltaPhi[DeltaPhi][2nmax,2nmax];
-
-    (* FIXME! *)
-    pols=Table[
-        PositiveMatrixWithPrefactor[DampedRational[1,{},rho,x], {{
-            Expand[
-                Expand[
-                    Expand[
-                        oddDerivs[nmax]/.addDeltaPhi
-                          ]/.zzbToRcTable[nmax]
-                      ]/.rcDerivPolTable[nmax][[L+1]]
-                  ]
-         }}],
-        {L,0,Lmax,2}
-    ];
-
-    unitOp=oddDerivs[nmax]/.addDeltaPhi/.{
-        zzbDeriv[0,0]->1,
-        zzbDeriv[_,_]->0
-    };
-
-    pols = MapAt[#/.x->x+DeltaScalarShift&,pols,1];
-    norm = unitOp;
-    obj = 0*unitOp;
-    WriteBootstrapSDP[datFile,SDP[obj,norm,pols]];
-];
diff --git a/mathematica/Tests.m b/mathematica/Tests.m
new file mode 100644
index 0000000..154f347
--- /dev/null
+++ b/mathematica/Tests.m
@@ -0,0 +1,44 @@
+(* Examples *)
+
+<<"SDPB.m";
+
+(* The following is the example in the manual *)
+(* Maximize {a,b}.{0,-1} = -b over {a,b} such that {a,b}.{1,0}=a=1 and 
+
+E^(-x)(a(1+x^4) + b(x^4/12 + x^2)) >= 0 for all x>=0
+
+Equivalently,
+
+1+x^4 + b(x^4/12 + x^2) >= 0 for all x >= 0
+
+The prefactor DampedRational[1,{},1/E,x] doesn't affect the answer,
+but does affect the choice of sample scalings and bilinear basis.
+
+*)
+testSDP[datFile_] := Module[
+    {
+        pols = {PositiveMatrixWithPrefactor[DampedRational[1,{}, 1/E,x], {{{1 + x^4, x^4/12 + x^2}}}]},
+        norm = {1, 0},
+        obj  = {0, -1}
+    },
+
+    WriteBootstrapSDP[datFile, SDP[obj, norm, pols]];];
+
+(* A similar computation to the above, except with nontrivial matrix semidefiniteness constraints *)
+testSDPMatrix[datFile_] := Module[
+    {
+        pols = {
+            PositiveMatrixWithPrefactor[
+                DampedRational[1, {}, 1/E, x],
+                {{{1 + x^4, 1 + x^4/12 + x^2}, {x^2,     x/5}},
+                 {{x^2,     x/5},              {2 + x^4, x^4/3 + 2*x^2}}}],
+            PositiveMatrixWithPrefactor[
+                DampedRational[1, {}, 1/E, x],
+                {{{1 + 3x^4/4, 1 + x^4/12 + x^2}, {x^2,     1/2 + x/5}},
+                 {{x^2,     1/2 + x/5},        {2 + 3x^4/5, x^4/3 + 2*x^2}}}]
+        },
+        norm = {1, 0},
+        obj  = {0, -1}
+    },
+
+    WriteBootstrapSDP[datFile, SDP[obj, norm, pols]];];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sdpb.git



More information about the debian-science-commits mailing list