1 /** @file exam_structure.cpp
3 * Small test for the structure<> template. */
6 * GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 using namespace GiNaC;
33 sprod_s(const ex & l, const ex & r) : left(l), right(r) {}
36 inline bool operator==(const sprod_s & lhs, const sprod_s & rhs)
38 return lhs.left.is_equal(rhs.left) && lhs.right.is_equal(rhs.right);
41 inline bool operator<(const sprod_s & lhs, const sprod_s & rhs)
43 return lhs.left.compare(rhs.left) < 0 ? true : lhs.right.compare(rhs.right) < 0;
46 typedef structure<sprod_s, compare_std_less> sprod;
48 inline ex make_sprod(const ex & l, const ex & r)
50 return sprod(sprod_s(l, r));
55 template <> void sprod::print(const print_context & c, unsigned level) const
57 const sprod_s & sp = get_struct();
58 c.s << "<" << sp.left << "|" << sp.right << ">";
61 template <> ex sprod::eval(int level) const
63 // symmetric scalar product
64 const sprod_s & sp = get_struct();
65 if (sp.left.compare(sp.right) <= 0)
68 return make_sprod(sp.right, sp.left);
73 unsigned exam_structure()
77 cout << "examining structure template" << flush;
79 symbol x("x"), y("y");
82 e = make_sprod(x, y) - make_sprod(y, x);
84 clog << "<x|y>-<y|x> erroneously returned " << e << " instead of 0" << endl;
90 e = make_sprod(x, x) - make_sprod(y, y);
92 clog << "<x|x>-<y|y> erroneously returned 0" << endl;
99 int main(int argc, char** argv)
101 return exam_structure();