|
GiNaC
1.6.2
|
00001 00005 /* 00006 * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef GINAC_EXPAIR_H 00024 #define GINAC_EXPAIR_H 00025 00026 #include "ex.h" 00027 #include "numeric.h" 00028 #include "print.h" 00029 00030 namespace GiNaC { 00031 00037 class expair 00038 { 00039 public: 00040 expair() : rest(0), coeff(1) { } 00041 00043 expair(const ex & r, const ex & c) : rest(r), coeff(c) 00044 { 00045 GINAC_ASSERT(is_exactly_a<numeric>(coeff)); 00046 } 00047 00049 bool is_equal(const expair & other) const 00050 { 00051 return (rest.is_equal(other.rest) && coeff.is_equal(other.coeff)); 00052 } 00053 00055 bool is_less(const expair & other) const 00056 { 00057 int restcmp = rest.compare(other.rest); 00058 return ((restcmp<0) || 00059 (!(restcmp>0) && (coeff.compare(other.coeff)<0))); 00060 } 00061 00063 int compare(const expair & other) const 00064 { 00065 int restcmp = rest.compare(other.rest); 00066 if (restcmp!=0) 00067 return restcmp; 00068 else 00069 return coeff.compare(other.coeff); 00070 } 00071 00072 void print(std::ostream & os) const; 00073 00075 bool is_canonical_numeric() const 00076 { 00077 GINAC_ASSERT(is_exactly_a<numeric>(coeff)); 00078 return (is_exactly_a<numeric>(rest) && (coeff.is_equal(1))); 00079 } 00080 00082 void swap(expair & other) 00083 { 00084 rest.swap(other.rest); 00085 coeff.swap(other.coeff); 00086 } 00087 00088 const expair conjugate() const; 00089 00090 ex rest; 00091 ex coeff; 00092 }; 00093 00095 struct expair_is_less : public std::binary_function<expair, expair, bool> { 00096 bool operator()(const expair &lh, const expair &rh) const { return lh.is_less(rh); } 00097 }; 00098 00103 struct expair_rest_is_less : public std::binary_function<expair, expair, bool> { 00104 bool operator()(const expair &lh, const expair &rh) const { return (lh.rest.compare(rh.rest)<0); } 00105 }; 00106 00107 struct expair_swap : public std::binary_function<expair, expair, void> { 00108 void operator()(expair &lh, expair &rh) const { lh.swap(rh); } 00109 }; 00110 00111 inline void swap(expair & e1, expair & e2) 00112 { e1.swap(e2); } 00113 00114 // This makes STL algorithms use the more efficient swap operation for ex objects 00115 inline void iter_swap(std::vector<expair>::iterator i1, std::vector<expair>::iterator i2) 00116 { i1->swap(*i2); } 00117 00118 } // namespace GiNaC 00119 00120 #endif // ndef GINAC_EXPAIR_H