From 8fa39ace650401ceaaf507e4b529ee30ad527828 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 7 Nov 2007 12:29:41 +0100 Subject: [PATCH] bernstein: rework testing framework to not depend on order of GiNaC expressions --- bernstein/Makefile.am | 2 +- bernstein/examples/README | 7 ++ bernstein/examples/basicLinear.matrix | 21 ++++ bernstein/examples/basicLinear.out | 34 ------ bernstein/examples/basicLinear2.matrix | 20 ++++ bernstein/examples/basicLinear2.out | 34 ------ bernstein/examples/basicTest.matrix | 10 ++ bernstein/examples/basicTest.out | 18 --- bernstein/examples/basicTestParameterPosNeg.matrix | 10 ++ bernstein/examples/basicTestParameterPosNeg.out | 19 ---- bernstein/examples/faddeev.matrix | 10 ++ bernstein/examples/faddeev.out | 18 --- bernstein/examples/linearExample.matrix | 22 ++++ bernstein/examples/linearExample.out | 36 ------ bernstein/examples/philippe.matrix | 10 ++ bernstein/examples/philippe.out | 21 ---- bernstein/examples/philippe3vars.matrix | 18 +++ bernstein/examples/philippe3vars.out | 36 ------ bernstein/examples/philippe3vars3pars.matrix | 22 ++++ bernstein/examples/philippe3vars3pars.out | 40 ------- bernstein/examples/philippeNeg.matrix | 10 ++ bernstein/examples/philippeNeg.out | 21 ---- bernstein/examples/philippePolynomialCoeff.matrix | 11 ++ bernstein/examples/philippePolynomialCoeff.out | 22 ---- .../examples/philippePolynomialCoeff1P.matrix | 10 ++ bernstein/examples/philippePolynomialCoeff1P.out | 21 ---- bernstein/examples/test3Deg3Var.matrix | 10 ++ bernstein/examples/test3Deg3Var.out | 19 ---- bernstein/examples/unexpanded.matrix | 9 ++ bernstein/examples/unexpanded.out | 24 ---- bernstein/src/main.cpp | 126 ++++++++++++++++++++- 31 files changed, 321 insertions(+), 370 deletions(-) delete mode 100644 bernstein/examples/basicLinear.out delete mode 100644 bernstein/examples/basicLinear2.out delete mode 100644 bernstein/examples/basicTest.out delete mode 100644 bernstein/examples/basicTestParameterPosNeg.out delete mode 100644 bernstein/examples/faddeev.out delete mode 100644 bernstein/examples/linearExample.out delete mode 100644 bernstein/examples/philippe.out delete mode 100644 bernstein/examples/philippe3vars.out delete mode 100644 bernstein/examples/philippe3vars3pars.out delete mode 100644 bernstein/examples/philippeNeg.out delete mode 100644 bernstein/examples/philippePolynomialCoeff.out delete mode 100644 bernstein/examples/philippePolynomialCoeff1P.out delete mode 100644 bernstein/examples/test3Deg3Var.out delete mode 100644 bernstein/examples/unexpanded.out diff --git a/bernstein/Makefile.am b/bernstein/Makefile.am index 598c652..adce094 100644 --- a/bernstein/Makefile.am +++ b/bernstein/Makefile.am @@ -25,7 +25,7 @@ EXTRA_DIST = examples check: @for i in $(top_srcdir)/examples/*.matrix; do \ - if ./bernstein < $$i | diff -u $${i%.matrix}.out -; then \ + if ./bernstein -T < $$i > /dev/null ; then \ echo "$$i passed"; \ else \ echo "$$i failed"; \ diff --git a/bernstein/examples/README b/bernstein/examples/README index c02dfe8..6707b65 100644 --- a/bernstein/examples/README +++ b/bernstein/examples/README @@ -4,6 +4,13 @@ The input of the bernstein executable consists of - a list of the names of the variables and the parameters - the parametric polynomial in GiNac notation +For verification, each of the examples also includes the expected solution, +consisting of the number of domains and for each domain +- the constraints in PolyLib notation +- a list of all corresponding coefficients +- a list of minimal coefficients +- a list of maximal coefficients + --------------------------------------------------------------------------- Brief description of examples: diff --git a/bernstein/examples/basicLinear.matrix b/bernstein/examples/basicLinear.matrix index 7ad292c..095f189 100644 --- a/bernstein/examples/basicLinear.matrix +++ b/bernstein/examples/basicLinear.matrix @@ -11,3 +11,24 @@ n m P Q n + +# the expected solution for verification +2 + +3 4 + 1 1 -1 0 + 1 0 1 -1 + 1 0 0 1 + +{1,Q} +{1} +{Q} + +3 4 + 1 -1 1 0 + 1 1 0 -1 + 1 0 0 1 + +{1,P} +{1} +{P} diff --git a/bernstein/examples/basicLinear.out b/bernstein/examples/basicLinear.out deleted file mode 100644 index 74ae87a..0000000 --- a/bernstein/examples/basicLinear.out +++ /dev/null @@ -1,34 +0,0 @@ - -=============================================== - -Domain: - P - Q >= 0 - Q -1 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - Q - 1 - Minimum coefficient(s): {1} - Maximum coefficient(s): {Q} - - -=============================================== - -Domain: - - P + Q >= 0 - P -1 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 1 - P - Minimum coefficient(s): {1} - Maximum coefficient(s): {P} - - -=============================================== diff --git a/bernstein/examples/basicLinear2.matrix b/bernstein/examples/basicLinear2.matrix index 5dcd5b4..651c93e 100644 --- a/bernstein/examples/basicLinear2.matrix +++ b/bernstein/examples/basicLinear2.matrix @@ -11,3 +11,23 @@ n m P Q n + +2 + +3 4 + 1 1 -1 1 + 1 0 1 -2 + 1 0 0 1 + +{P,-1+Q} +{-1+Q} +{P} + +3 4 + 1 1 0 -1 + 1 0 -1 2 + 1 0 0 1 + +{P,1} +{1} +{P} diff --git a/bernstein/examples/basicLinear2.out b/bernstein/examples/basicLinear2.out deleted file mode 100644 index 1f244d2..0000000 --- a/bernstein/examples/basicLinear2.out +++ /dev/null @@ -1,34 +0,0 @@ - -=============================================== - -Domain: - P - Q + 1 >= 0 - Q -2 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - P - -1+Q - Minimum coefficient(s): {-1+Q} - Maximum coefficient(s): {P} - - -=============================================== - -Domain: - P -1 >= 0 - - Q + 2 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 1 - P - Minimum coefficient(s): {1} - Maximum coefficient(s): {P} - - -=============================================== diff --git a/bernstein/examples/basicTest.matrix b/bernstein/examples/basicTest.matrix index 4c5336e..2f79bde 100644 --- a/bernstein/examples/basicTest.matrix +++ b/bernstein/examples/basicTest.matrix @@ -10,3 +10,13 @@ n m p n^2+n + +1 + +2 3 + 1 1 -1 + 1 0 1 + +{ p+p^2, 2, 1/2+3/2*p } +{2} +{p+p^2} diff --git a/bernstein/examples/basicTest.out b/bernstein/examples/basicTest.out deleted file mode 100644 index 3faadaf..0000000 --- a/bernstein/examples/basicTest.out +++ /dev/null @@ -1,18 +0,0 @@ - -=============================================== - -Domain: - p -1 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - p+p^2 - 2 - 1/2+3/2*p - Minimum coefficient(s): {2} - Maximum coefficient(s): {p+p^2} - - -=============================================== diff --git a/bernstein/examples/basicTestParameterPosNeg.matrix b/bernstein/examples/basicTestParameterPosNeg.matrix index 35d0c84..da38557 100644 --- a/bernstein/examples/basicTestParameterPosNeg.matrix +++ b/bernstein/examples/basicTestParameterPosNeg.matrix @@ -10,3 +10,13 @@ n m p n^3+n + +1 + +2 3 + 1 1 1 + 1 0 1 + +{ -2, -1/3+2/3*p-p^2, p+p^3, -2/3+4/3*p } +{-2,-1/3+2/3*p-p^2,p+p^3} +{-1/3+2/3*p-p^2,p+p^3,-2/3+4/3*p} diff --git a/bernstein/examples/basicTestParameterPosNeg.out b/bernstein/examples/basicTestParameterPosNeg.out deleted file mode 100644 index c853038..0000000 --- a/bernstein/examples/basicTestParameterPosNeg.out +++ /dev/null @@ -1,19 +0,0 @@ - -=============================================== - -Domain: - p + 1 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - -2 - -1/3+2/3*p-p^2 - p+p^3 - -2/3+4/3*p - Minimum coefficient(s): {-2,-1/3+2/3*p-p^2,p+p^3} - Maximum coefficient(s): {-1/3+2/3*p-p^2,p+p^3,-2/3+4/3*p} - - -=============================================== diff --git a/bernstein/examples/faddeev.matrix b/bernstein/examples/faddeev.matrix index b093c0d..ff96358 100644 --- a/bernstein/examples/faddeev.matrix +++ b/bernstein/examples/faddeev.matrix @@ -11,3 +11,13 @@ i j k N 4+6*N+2*N^2+k*(-2-N)+j*(-2-2*N)+k*j + +1 + +2 3 + 1 -1 100 + 1 1 -10 + +{ 4-6*N+2*N^2, -2+1/2*N+1/2*N^2, 1+N} +{1+N} +{4-6*N+2*N^2} diff --git a/bernstein/examples/faddeev.out b/bernstein/examples/faddeev.out deleted file mode 100644 index 46047c6..0000000 --- a/bernstein/examples/faddeev.out +++ /dev/null @@ -1,18 +0,0 @@ - -=============================================== - -Domain: - - N + 100 >= 0 - N -10 >= 0 - ------------------------------------------------ -Coefficients: - - 4-6*N+2*N^2 - -2+1/2*N+1/2*N^2 - 1+N - Minimum coefficient(s): {1+N} - Maximum coefficient(s): {4-6*N+2*N^2} - - -=============================================== diff --git a/bernstein/examples/linearExample.matrix b/bernstein/examples/linearExample.matrix index 2b81eca..25d08ed 100644 --- a/bernstein/examples/linearExample.matrix +++ b/bernstein/examples/linearExample.matrix @@ -12,3 +12,25 @@ i j k N M L 1/7*k+5*j+1/2*i + +2 + +4 5 + 1 0 1 1 0 + 1 1 -1 -1 0 + 1 0 0 1 0 + 1 0 0 0 1 + +{ 34/7*L-1/7*M, 75/28*N+61/28*L-79/28*M } +{34/7*L-1/7*M} +{75/28*N+61/28*L-79/28*M} + +4 5 + 1 0 1 1 0 + 1 -1 1 1 0 + 1 0 0 1 0 + 1 0 0 0 1 + +{ -1/7*N+5*L, 34/7*N-5*M } +{34/7*N-5*M} +{-1/7*N+5*L} diff --git a/bernstein/examples/linearExample.out b/bernstein/examples/linearExample.out deleted file mode 100644 index 3da4350..0000000 --- a/bernstein/examples/linearExample.out +++ /dev/null @@ -1,36 +0,0 @@ - -=============================================== - -Domain: - M + L >= 0 - N - M - L >= 0 - L >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 34/7*L-1/7*M - 75/28*N+61/28*L-79/28*M - Minimum coefficient(s): {34/7*L-1/7*M} - Maximum coefficient(s): {75/28*N+61/28*L-79/28*M} - - -=============================================== - -Domain: - M + L >= 0 - - N + M + L >= 0 - L >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - -1/7*N+5*L - 34/7*N-5*M - Minimum coefficient(s): {34/7*N-5*M} - Maximum coefficient(s): {-1/7*N+5*L} - - -=============================================== diff --git a/bernstein/examples/philippe.matrix b/bernstein/examples/philippe.matrix index e6eafba..2d2ef3d 100644 --- a/bernstein/examples/philippe.matrix +++ b/bernstein/examples/philippe.matrix @@ -10,3 +10,13 @@ i j N j+1/2*i^2+1/2*i + +1 + +2 3 + 1 1 0 + 1 0 1 + +{ 0, 3/2*N+1/2*N^2, 1/4*N, 1/2*N+1/2*N^2, 3/4*N, N+1/2*N^2} +{0} +{3/2*N+1/2*N^2} diff --git a/bernstein/examples/philippe.out b/bernstein/examples/philippe.out deleted file mode 100644 index f8706a2..0000000 --- a/bernstein/examples/philippe.out +++ /dev/null @@ -1,21 +0,0 @@ - -=============================================== - -Domain: - N >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 0 - 3/2*N+1/2*N^2 - 1/4*N - 1/2*N+1/2*N^2 - 3/4*N - N+1/2*N^2 - Minimum coefficient(s): {0} - Maximum coefficient(s): {3/2*N+1/2*N^2} - - -=============================================== diff --git a/bernstein/examples/philippe3vars.matrix b/bernstein/examples/philippe3vars.matrix index 8417270..5fe67d4 100644 --- a/bernstein/examples/philippe3vars.matrix +++ b/bernstein/examples/philippe3vars.matrix @@ -10,3 +10,21 @@ i j k N j+1/2*i^2+1/2*i+k^3 + +2 + +2 3 + 1 1 0 + 1 0 1 + +{ 0, 3/4*N+1/8*N^2-1/8*N^3, 1/4*N, 1/2*N+1/24*N^2 } +{0,3/4*N+1/8*N^2-1/8*N^3} +{3/4*N+1/8*N^2-1/8*N^3,1/2*N+1/24*N^2} + +2 3 + 1 -1 0 + 1 0 1 + +{ 1/3*N-N^3, N-N^3, -N^3, 2/3*N-N^3 } +{N-N^3} +{-N^3} diff --git a/bernstein/examples/philippe3vars.out b/bernstein/examples/philippe3vars.out deleted file mode 100644 index d83a6e1..0000000 --- a/bernstein/examples/philippe3vars.out +++ /dev/null @@ -1,36 +0,0 @@ - -=============================================== - -Domain: - N >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 0 - 3/4*N+1/8*N^2-1/8*N^3 - 1/4*N - 1/2*N+1/24*N^2 - Minimum coefficient(s): {0,3/4*N+1/8*N^2-1/8*N^3} - Maximum coefficient(s): {3/4*N+1/8*N^2-1/8*N^3,1/2*N+1/24*N^2} - - -=============================================== - -Domain: - - N >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 1/3*N-N^3 - N-N^3 - -N^3 - 2/3*N-N^3 - Minimum coefficient(s): {N-N^3} - Maximum coefficient(s): {-N^3} - - -=============================================== diff --git a/bernstein/examples/philippe3vars3pars.matrix b/bernstein/examples/philippe3vars3pars.matrix index 5edde78..ee9a310 100644 --- a/bernstein/examples/philippe3vars3pars.matrix +++ b/bernstein/examples/philippe3vars3pars.matrix @@ -12,3 +12,25 @@ i j k N M L j+1/2*i^2+1/2*i+k^3 + +2 + +4 5 + 1 0 1 1 0 + 1 1 -1 -1 0 + 1 0 0 1 0 + 1 0 0 0 1 + +{ 1/4*N-N*L*M-1/2*N*L^2-3/2*L^2*M-1/2*N*M^2+3/4*L-1/4*M-1/2*M^3-3/2*L*M^2-1/2*L^3, 3/4*N-3/4*N*L*M-1/4*N*M-1/4*N*L-3/8*N*L^2-3/8*L^2*M-3/8*N*M^2+1/4*L*M+1/8*N^2+1/4*L-1/8*N^3-3/4*M-3/8*N^2*L+1/8*L^2-1/8*M^3-3/8*L*M^2-3/8*N^2*M+1/8*M^2-1/8*L^3, -3*L^2*M+L-M^3-3*L*M^2-L^3, 1/2*N-N*L*M-1/12*N*M-1/12*N*L-1/2*N*L^2-3/4*L^2*M-1/2*N*M^2+1/12*L*M+1/24*N^2+1/2*L-1/2*M-1/4*N^2*L+1/24*L^2-1/4*M^3-3/4*L*M^2-1/4*N^2*M+1/24*M^2-1/4*L^3 } +{1/4*N-N*L*M-1/2*N*L^2-3/2*L^2*M-1/2*N*M^2+3/4*L-1/4*M-1/2*M^3-3/2*L*M^2-1/2*L^3,3/4*N-3/4*N*L*M-1/4*N*M-1/4*N*L-3/8*N*L^2-3/8*L^2*M-3/8*N*M^2+1/4*L*M+1/8*N^2+1/4*L-1/8*N^3-3/4*M-3/8*N^2*L+1/8*L^2-1/8*M^3-3/8*L*M^2-3/8*N^2*M+1/8*M^2-1/8*L^3,-3*L^2*M+L-M^3-3*L*M^2-L^3,1/2*N-N*L*M-1/12*N*M-1/12*N*L-1/2*N*L^2-3/4*L^2*M-1/2*N*M^2+1/12*L*M+1/24*N^2+1/2*L-1/2*M-1/4*N^2*L+1/24*L^2-1/4*M^3-3/4*L*M^2-1/4*N^2*M+1/24*M^2-1/4*L^3} +{1/4*N-N*L*M-1/2*N*L^2-3/2*L^2*M-1/2*N*M^2+3/4*L-1/4*M-1/2*M^3-3/2*L*M^2-1/2*L^3,3/4*N-3/4*N*L*M-1/4*N*M-1/4*N*L-3/8*N*L^2-3/8*L^2*M-3/8*N*M^2+1/4*L*M+1/8*N^2+1/4*L-1/8*N^3-3/4*M-3/8*N^2*L+1/8*L^2-1/8*M^3-3/8*L*M^2-3/8*N^2*M+1/8*M^2-1/8*L^3,-3*L^2*M+L-M^3-3*L*M^2-L^3,1/2*N-N*L*M-1/12*N*M-1/12*N*L-1/2*N*L^2-3/4*L^2*M-1/2*N*M^2+1/12*L*M+1/24*N^2+1/2*L-1/2*M-1/4*N^2*L+1/24*L^2-1/4*M^3-3/4*L*M^2-1/4*N^2*M+1/24*M^2-1/4*L^3} + +4 5 + 1 0 1 1 0 + 1 -1 1 1 0 + 1 0 0 1 0 + 1 0 0 0 1 + +{ L-N^3, 1/3*N+2/3*L-N^3-1/3*M, N-N^3-M, 2/3*N+1/3*L-N^3-2/3*M } +{N-N^3-M} +{L-N^3} diff --git a/bernstein/examples/philippe3vars3pars.out b/bernstein/examples/philippe3vars3pars.out deleted file mode 100644 index f4ac6ef..0000000 --- a/bernstein/examples/philippe3vars3pars.out +++ /dev/null @@ -1,40 +0,0 @@ - -=============================================== - -Domain: - M + L >= 0 - N - M - L >= 0 - L >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 1/4*N-N*L*M-1/2*N*L^2-3/2*L^2*M-1/2*N*M^2+3/4*L-1/4*M-1/2*M^3-3/2*L*M^2-1/2*L^3 - 3/4*N-3/4*N*L*M-1/4*N*M-1/4*N*L-3/8*N*L^2-3/8*L^2*M-3/8*N*M^2+1/4*L*M+1/8*N^2+1/4*L-1/8*N^3-3/4*M-3/8*N^2*L+1/8*L^2-1/8*M^3-3/8*L*M^2-3/8*N^2*M+1/8*M^2-1/8*L^3 - -3*L^2*M+L-M^3-3*L*M^2-L^3 - 1/2*N-N*L*M-1/12*N*M-1/12*N*L-1/2*N*L^2-3/4*L^2*M-1/2*N*M^2+1/12*L*M+1/24*N^2+1/2*L-1/2*M-1/4*N^2*L+1/24*L^2-1/4*M^3-3/4*L*M^2-1/4*N^2*M+1/24*M^2-1/4*L^3 - Minimum coefficient(s): {1/4*N-N*L*M-1/2*N*L^2-3/2*L^2*M-1/2*N*M^2+3/4*L-1/4*M-1/2*M^3-3/2*L*M^2-1/2*L^3,3/4*N-3/4*N*L*M-1/4*N*M-1/4*N*L-3/8*N*L^2-3/8*L^2*M-3/8*N*M^2+1/4*L*M+1/8*N^2+1/4*L-1/8*N^3-3/4*M-3/8*N^2*L+1/8*L^2-1/8*M^3-3/8*L*M^2-3/8*N^2*M+1/8*M^2-1/8*L^3,-3*L^2*M+L-M^3-3*L*M^2-L^3,1/2*N-N*L*M-1/12*N*M-1/12*N*L-1/2*N*L^2-3/4*L^2*M-1/2*N*M^2+1/12*L*M+1/24*N^2+1/2*L-1/2*M-1/4*N^2*L+1/24*L^2-1/4*M^3-3/4*L*M^2-1/4*N^2*M+1/24*M^2-1/4*L^3} - Maximum coefficient(s): {1/4*N-N*L*M-1/2*N*L^2-3/2*L^2*M-1/2*N*M^2+3/4*L-1/4*M-1/2*M^3-3/2*L*M^2-1/2*L^3,3/4*N-3/4*N*L*M-1/4*N*M-1/4*N*L-3/8*N*L^2-3/8*L^2*M-3/8*N*M^2+1/4*L*M+1/8*N^2+1/4*L-1/8*N^3-3/4*M-3/8*N^2*L+1/8*L^2-1/8*M^3-3/8*L*M^2-3/8*N^2*M+1/8*M^2-1/8*L^3,-3*L^2*M+L-M^3-3*L*M^2-L^3,1/2*N-N*L*M-1/12*N*M-1/12*N*L-1/2*N*L^2-3/4*L^2*M-1/2*N*M^2+1/12*L*M+1/24*N^2+1/2*L-1/2*M-1/4*N^2*L+1/24*L^2-1/4*M^3-3/4*L*M^2-1/4*N^2*M+1/24*M^2-1/4*L^3} - - -=============================================== - -Domain: - M + L >= 0 - - N + M + L >= 0 - L >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - L-N^3 - 1/3*N+2/3*L-N^3-1/3*M - N-N^3-M - 2/3*N+1/3*L-N^3-2/3*M - Minimum coefficient(s): {N-N^3-M} - Maximum coefficient(s): {L-N^3} - - -=============================================== diff --git a/bernstein/examples/philippeNeg.matrix b/bernstein/examples/philippeNeg.matrix index 1d9192d..dda8b78 100644 --- a/bernstein/examples/philippeNeg.matrix +++ b/bernstein/examples/philippeNeg.matrix @@ -10,3 +10,13 @@ i j N j+1/2*i^2+1/2*i + +1 + +2 3 + 1 1 1 + 1 0 1 + +{ 3/2*N+1/2*N^2, -5/4-1/4*N, -1/2+N+1/2*N^2, -1+1/2*N+1/2*N^2, -3/4+1/4*N, -1 } +{-5/4-1/4*N,-1+1/2*N+1/2*N^2} +{3/2*N+1/2*N^2,-3/4+1/4*N} diff --git a/bernstein/examples/philippeNeg.out b/bernstein/examples/philippeNeg.out deleted file mode 100644 index db4d71a..0000000 --- a/bernstein/examples/philippeNeg.out +++ /dev/null @@ -1,21 +0,0 @@ - -=============================================== - -Domain: - N + 1 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 3/2*N+1/2*N^2 - -5/4-1/4*N - -1/2+N+1/2*N^2 - -1+1/2*N+1/2*N^2 - -3/4+1/4*N - -1 - Minimum coefficient(s): {-5/4-1/4*N,-1+1/2*N+1/2*N^2} - Maximum coefficient(s): {3/2*N+1/2*N^2,-3/4+1/4*N} - - -=============================================== diff --git a/bernstein/examples/philippePolynomialCoeff.matrix b/bernstein/examples/philippePolynomialCoeff.matrix index 67748b0..d36644a 100644 --- a/bernstein/examples/philippePolynomialCoeff.matrix +++ b/bernstein/examples/philippePolynomialCoeff.matrix @@ -11,3 +11,14 @@ i j N M (1/5*N+N^2)*i^2+5*j+N*i + +1 + +3 4 + 1 0 1 0 + 1 1 0 0 + 1 0 0 1 + +{ 0, N^4+1/5*N^3+N^2, 5*N+N^4+1/5*N^3+N^2, 5/2*N+1/2*N^2, 5/2*N+N^4+1/5*N^3+N^2, 1/2*N^2} +{0} +{5*N+N^4+1/5*N^3+N^2} diff --git a/bernstein/examples/philippePolynomialCoeff.out b/bernstein/examples/philippePolynomialCoeff.out deleted file mode 100644 index 3bc0b55..0000000 --- a/bernstein/examples/philippePolynomialCoeff.out +++ /dev/null @@ -1,22 +0,0 @@ - -=============================================== - -Domain: - M >= 0 - N >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 0 - N^4+1/5*N^3+N^2 - 5*N+N^4+1/5*N^3+N^2 - 5/2*N+1/2*N^2 - 5/2*N+N^4+1/5*N^3+N^2 - 1/2*N^2 - Minimum coefficient(s): {0} - Maximum coefficient(s): {5*N+N^4+1/5*N^3+N^2} - - -=============================================== diff --git a/bernstein/examples/philippePolynomialCoeff1P.matrix b/bernstein/examples/philippePolynomialCoeff1P.matrix index 648cf8e..18b9456 100644 --- a/bernstein/examples/philippePolynomialCoeff1P.matrix +++ b/bernstein/examples/philippePolynomialCoeff1P.matrix @@ -10,3 +10,13 @@ i j N (1/5*N+N^2)*i^2+5*j+N*i + +1 + +2 3 + 1 1 0 + 1 0 1 + +{ 0, N^4+1/5*N^3+N^2, 5*N+N^4+1/5*N^3+N^2, 5/2*N+1/2*N^2, 5/2*N+N^4+1/5*N^3+N^2, 1/2*N^2 } +{0} +{5*N+N^4+1/5*N^3+N^2} diff --git a/bernstein/examples/philippePolynomialCoeff1P.out b/bernstein/examples/philippePolynomialCoeff1P.out deleted file mode 100644 index 1c2c8c4..0000000 --- a/bernstein/examples/philippePolynomialCoeff1P.out +++ /dev/null @@ -1,21 +0,0 @@ - -=============================================== - -Domain: - N >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 0 - N^4+1/5*N^3+N^2 - 5*N+N^4+1/5*N^3+N^2 - 5/2*N+1/2*N^2 - 5/2*N+N^4+1/5*N^3+N^2 - 1/2*N^2 - Minimum coefficient(s): {0} - Maximum coefficient(s): {5*N+N^4+1/5*N^3+N^2} - - -=============================================== diff --git a/bernstein/examples/test3Deg3Var.matrix b/bernstein/examples/test3Deg3Var.matrix index d7a20fe..1fe4a77 100644 --- a/bernstein/examples/test3Deg3Var.matrix +++ b/bernstein/examples/test3Deg3Var.matrix @@ -10,3 +10,13 @@ n m p n^3+n + +1 + +2 3 + 1 1 -1 + 1 0 1 + +{ 2/3+4/3*p, p+p^3, 2, 1/3+2/3*p+p^2} +{2} +{p+p^3} diff --git a/bernstein/examples/test3Deg3Var.out b/bernstein/examples/test3Deg3Var.out deleted file mode 100644 index b0639f1..0000000 --- a/bernstein/examples/test3Deg3Var.out +++ /dev/null @@ -1,19 +0,0 @@ - -=============================================== - -Domain: - p -1 >= 0 - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 2/3+4/3*p - p+p^3 - 2 - 1/3+2/3*p+p^2 - Minimum coefficient(s): {2} - Maximum coefficient(s): {p+p^3} - - -=============================================== diff --git a/bernstein/examples/unexpanded.matrix b/bernstein/examples/unexpanded.matrix index 16283c9..3892c8f 100644 --- a/bernstein/examples/unexpanded.matrix +++ b/bernstein/examples/unexpanded.matrix @@ -9,3 +9,12 @@ x y x*(1-x)*y*(1-y) + +1 + +1 2 + 1 1 + +{ 0, 1, -2, 2/3, 4/3, -1/3, 4, -1, 1/3, -2/3 } +{-2} +{4} diff --git a/bernstein/examples/unexpanded.out b/bernstein/examples/unexpanded.out deleted file mode 100644 index 0679ebf..0000000 --- a/bernstein/examples/unexpanded.out +++ /dev/null @@ -1,24 +0,0 @@ - -=============================================== - -Domain: - 1 >= 0 - ------------------------------------------------ -Coefficients: - - 0 - 1 - -2 - 2/3 - 4/3 - -1/3 - 4 - -1 - 1/3 - -2/3 - Minimum coefficient(s): {-2} - Maximum coefficient(s): {4} - - -=============================================== diff --git a/bernstein/src/main.cpp b/bernstein/src/main.cpp index ba2b3a7..31ee98c 100644 --- a/bernstein/src/main.cpp +++ b/bernstein/src/main.cpp @@ -1,5 +1,7 @@ +#include #include #include +#include #include #include @@ -7,6 +9,7 @@ #include #include +#include #define MAXRAYS 1000 @@ -18,19 +21,86 @@ static ex readPolynomial(const exvector& vars, const exvector& params); static void printCoefficients(lst coeffs); static int printMaxMinCoefficient(Polyhedron *VD, lst coeffs, const exvector& Params); +static char *readLine(void) +{ + static char buffer[1024]; + char *s; + + do + s = fgets(buffer, 1024, stdin); + while (s && (s[0] == '#' || s[0] == '\n')); + + return s; +} + +static void readExpected(const exvector& vars, const exvector& params, + piecewise_lst **exp_all, + piecewise_lst **exp_min, + piecewise_lst **exp_max) +{ + int n = 0; + char *s; + piecewise_lst *pl_all, *pl_min, *pl_max; + + pl_all = new piecewise_lst(params); + pl_min = new piecewise_lst(params); + pl_max = new piecewise_lst(params); + + s = readLine(); + assert(s); + + sscanf(s, "%d", &n); + + for (int i = 0 ; i < n ; ++i) { + ex all, min, max; + Polyhedron *D; + Matrix *M = Matrix_Read(); + + D = Constraints2Polyhedron(M, MAXRAYS); + Matrix_Free(M); + + all = readPolynomial(vars, params); + min = readPolynomial(vars, params); + max = readPolynomial(vars, params); + assert(is_a(all)); + assert(is_a(min)); + assert(is_a(max)); + pl_all->add_guarded_lst(Polyhedron_Copy(D), ex_to(all)); + pl_min->add_guarded_lst(Polyhedron_Copy(D), ex_to(min)); + pl_max->add_guarded_lst(D, ex_to(max)); + } + *exp_all = pl_all; + *exp_min = pl_min; + *exp_max = pl_max; +} + /* main function */ -int main(void) { +int main(int argc, char *argv[]) +{ Matrix *a, *b; Polyhedron *A, *B; // initial matrices char **param_name; // name of the parameters exvector params, vars; ex polynomial; + piecewise_lst *exp_all, *exp_min, *exp_max; + piecewise_lst *got_all, *got_min, *got_max; Param_Polyhedron *PP; Param_Domain *Q; unsigned int nb_param, nb_var; + int c; + int verify = 0; + + while ((c = getopt(argc, argv, "T")) != -1) { + switch(c) { + case 'T': + verify = 1; + break; + } + } + printf("\n===============================================\n"); a = Matrix_Read(); @@ -50,6 +120,13 @@ int main(void) { polynomial = readPolynomial(vars, params); + if (verify) { + readExpected(vars, params, &exp_all, &exp_min, &exp_max); + got_all = new piecewise_lst(params); + got_min = new piecewise_lst(params); + got_max = new piecewise_lst(params); + } + Matrix_Free(a); Matrix_Free(b); @@ -68,6 +145,15 @@ int main(void) { printMaxMinCoefficient(Q->Domain, coeffs, params); Domain_Free(VD); printf("\n\n===============================================\n"); + + if (!verify) + continue; + + got_all->add_guarded_lst(Polyhedron_Copy(Q->Domain), coeffs); + got_min->add_guarded_lst(Polyhedron_Copy(Q->Domain), + minimize(Q->Domain, coeffs, params)); + got_max->add_guarded_lst(Polyhedron_Copy(Q->Domain), + maximize(Q->Domain, coeffs, params)); } Domain_Free(A); @@ -75,6 +161,37 @@ int main(void) { Param_Polyhedron_Free(PP); free(param_name); + if (verify) { + if (!got_all->is_equal(*exp_all)) { + cerr << "expected:" << endl; + cerr << *exp_all << endl; + cerr << "got:" << endl; + cerr << *got_all << endl; + return 1; + } + if (!got_min->is_equal(*exp_min)) { + cerr << "expected:" << endl; + cerr << *exp_min << endl; + cerr << "got:" << endl; + cerr << *got_min << endl; + return 1; + } + if (!got_max->is_equal(*exp_max)) { + cerr << "expected:" << endl; + cerr << *exp_max << endl; + cerr << "got:" << endl; + cerr << *got_max << endl; + return 1; + } + + delete exp_all; + delete exp_max; + delete exp_min; + delete got_all; + delete got_max; + delete got_min; + } + return 0; } /* main */ @@ -92,7 +209,7 @@ void printCoefficients(lst coeffs) /* Reads the polynomial matrix, converts it to long long precision and calls ginac functions */ ex readPolynomial(const exvector& vars, const exvector& params) { - char buffer[1024], *s; + char *s; lst allvars; ex p; @@ -101,10 +218,7 @@ ex readPolynomial(const exvector& vars, const exvector& params) for (int i = 0; i < params.size(); ++i) allvars.append(params[i]); - do - s = fgets(buffer, 1024, stdin); - while (s && (s[0] == '#' || s[0] == '\n')); - + s = readLine(); if (!s) return 0; -- 2.11.4.GIT