X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_matrices.cpp;h=9a88c8c2bc80af55f7f3197ade0828280d8f465f;hp=a032bfe8bb891577d162e170a0006c5b868d497d;hb=fa048d7e0e3c7bcde12f0c7d3d3c428fc9782884;hpb=af922d5eb36ed70e4a9e3ffaf4c24492cf89a1a6 diff --git a/check/exam_matrices.cpp b/check/exam_matrices.cpp index a032bfe8..9a88c8c2 100644 --- a/check/exam_matrices.cpp +++ b/check/exam_matrices.cpp @@ -3,7 +3,7 @@ * Here we examine manipulations on GiNaC's symbolic matrices. */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ #include #include "exams.h" -static unsigned matrix_determinants(void) +static unsigned matrix_determinants() { unsigned result = 0; ex det; @@ -37,7 +37,7 @@ static unsigned matrix_determinants(void) det = m1.determinant(); if (det != a) { clog << "determinant of 1x1 matrix " << m1 - << " erroneously returned " << det << endl; + << " erroneously returned " << det << endl; ++result; } @@ -47,7 +47,7 @@ static unsigned matrix_determinants(void) det = m2.determinant(); if (det != (a*d-b*c)) { clog << "determinant of 2x2 matrix " << m2 - << " erroneously returned " << det << endl; + << " erroneously returned " << det << endl; ++result; } @@ -58,7 +58,7 @@ static unsigned matrix_determinants(void) det = m3.determinant(); if (det != (a*e*i - a*f*h - d*b*i + d*c*h + g*b*f - g*c*e)) { clog << "determinant of 3x3 matrix " << m3 - << " erroneously returned " << det << endl; + << " erroneously returned " << det << endl; ++result; } @@ -69,7 +69,7 @@ static unsigned matrix_determinants(void) det = m3.determinant(); if (det != 42) { clog << "determinant of 3x3 matrix " << m3 - << " erroneously returned " << det << endl; + << " erroneously returned " << det << endl; ++result; } @@ -80,10 +80,10 @@ static unsigned matrix_determinants(void) if (det != 1) { if (det.normal() == 1) // only half wrong clog << "determinant of 2x2 matrix " << m2 - << " was returned unnormalized as " << det << endl; + << " was returned unnormalized as " << det << endl; else // totally wrong clog << "determinant of 2x2 matrix " << m2 - << " erroneously returned " << det << endl; + << " erroneously returned " << det << endl; ++result; } @@ -92,7 +92,7 @@ static unsigned matrix_determinants(void) det = m4.determinant(); if (det != a*b*c*d) { clog << "determinant of 4x4 matrix " << m4 - << " erroneously returned " << det << endl; + << " erroneously returned " << det << endl; ++result; } @@ -103,14 +103,14 @@ static unsigned matrix_determinants(void) ex p = m3.charpoly(a); if (p != 0) { clog << "charpoly of 3x3 matrix " << m3 - << " erroneously returned " << p << endl; + << " erroneously returned " << p << endl; ++result; } return result; } -static unsigned matrix_invert1(void) +static unsigned matrix_invert1() { unsigned result = 0; matrix m(1,1); @@ -121,14 +121,14 @@ static unsigned matrix_invert1(void) if (m_i(0,0) != pow(a,-1)) { clog << "inversion of 1x1 matrix " << m - << " erroneously returned " << m_i << endl; + << " erroneously returned " << m_i << endl; ++result; } return result; } -static unsigned matrix_invert2(void) +static unsigned matrix_invert2() { unsigned result = 0; matrix m(2,2); @@ -143,14 +143,14 @@ static unsigned matrix_invert2(void) (normal(m_i(1,0)*det) != -c) || (normal(m_i(1,1)*det) != a)) { clog << "inversion of 2x2 matrix " << m - << " erroneously returned " << m_i << endl; + << " erroneously returned " << m_i << endl; ++result; } return result; } -static unsigned matrix_invert3(void) +static unsigned matrix_invert3() { unsigned result = 0; matrix m(3,3); @@ -164,23 +164,23 @@ static unsigned matrix_invert3(void) ex det = m.determinant(); if ((normal(m_i(0,0)*det) != (e*i-f*h)) || - (normal(m_i(0,1)*det) != (c*h-b*i)) || - (normal(m_i(0,2)*det) != (b*f-c*e)) || - (normal(m_i(1,0)*det) != (f*g-d*i)) || - (normal(m_i(1,1)*det) != (a*i-c*g)) || - (normal(m_i(1,2)*det) != (c*d-a*f)) || - (normal(m_i(2,0)*det) != (d*h-e*g)) || - (normal(m_i(2,1)*det) != (b*g-a*h)) || - (normal(m_i(2,2)*det) != (a*e-b*d))) { + (normal(m_i(0,1)*det) != (c*h-b*i)) || + (normal(m_i(0,2)*det) != (b*f-c*e)) || + (normal(m_i(1,0)*det) != (f*g-d*i)) || + (normal(m_i(1,1)*det) != (a*i-c*g)) || + (normal(m_i(1,2)*det) != (c*d-a*f)) || + (normal(m_i(2,0)*det) != (d*h-e*g)) || + (normal(m_i(2,1)*det) != (b*g-a*h)) || + (normal(m_i(2,2)*det) != (a*e-b*d))) { clog << "inversion of 3x3 matrix " << m - << " erroneously returned " << m_i << endl; + << " erroneously returned " << m_i << endl; ++result; } return result; } -static unsigned matrix_solve2(void) +static unsigned matrix_solve2() { // check the solution of the multiple system A*X = B: // [ 1 2 -1 ] [ x0 y0 ] [ 4 0 ] @@ -210,13 +210,38 @@ static unsigned matrix_solve2(void) result = 1; if (result) { clog << "Solving " << A << " * " << X << " == " << B << endl - << "erroneously returned " << sol << endl; + << "erroneously returned " << sol << endl; } return result; } -static unsigned matrix_misc(void) +static unsigned matrix_evalm() +{ + unsigned result = 0; + + matrix S(2, 2, lst( + 1, 2, + 3, 4 + )), T(2, 2, lst( + 1, 1, + 2, -1 + )), R(2, 2, lst( + 27, 14, + 36, 26 + )); + + ex e = ((S + T) * (S + 2*T)); + ex f = e.evalm(); + if (!f.is_equal(R)) { + clog << "Evaluating " << e << " erroneously returned " << f << " instead of " << R << endl; + result++; + } + + return result; +} + +static unsigned matrix_misc() { unsigned result = 0; matrix m1(2,2); @@ -228,7 +253,7 @@ static unsigned matrix_misc(void) // check a simple trace if (tr.compare(a+d)) { clog << "trace of 2x2 matrix " << m1 - << " erroneously returned " << tr << endl; + << " erroneously returned " << tr << endl; ++result; } @@ -245,7 +270,7 @@ static unsigned matrix_misc(void) m3.set(2,0,e).set(2,1,f); if (transpose(transpose(m3)) != m3) { clog << "transposing 3x2 matrix " << m3 << " twice" - << " erroneously returned " << transpose(transpose(m3)) << endl; + << " erroneously returned " << transpose(transpose(m3)) << endl; ++result; } @@ -260,14 +285,14 @@ static unsigned matrix_misc(void) } if (!caught) { cerr << "singular 2x2 matrix " << m4 - << " erroneously inverted to " << m5 << endl; + << " erroneously inverted to " << m5 << endl; ++result; } return result; } -unsigned exam_matrices(void) +unsigned exam_matrices() { unsigned result = 0; @@ -279,6 +304,7 @@ unsigned exam_matrices(void) result += matrix_invert2(); cout << '.' << flush; result += matrix_invert3(); cout << '.' << flush; result += matrix_solve2(); cout << '.' << flush; + result += matrix_evalm(); cout << "." << flush; result += matrix_misc(); cout << '.' << flush; if (!result) {