3 /** A pair of expressions.
4 * This similar to, but slightly extended STL's pair<> but we need to account
5 * for methods like .compare() */
11 expair(expair const & other) : rest(other.rest), coeff(other.coeff)
13 ASSERT(is_ex_exactly_of_type(coeff,numeric));
15 expair const & operator=(expair const & other)
23 expair(ex const & r, ex const & c) : rest(r), coeff(c)
25 ASSERT(is_ex_exactly_of_type(coeff,numeric));
28 bool is_numeric_with_coeff_1(void) const
30 ASSERT(is_ex_exactly_of_type(coeff,numeric));
31 return is_ex_exactly_of_type(rest,numeric) &&
32 (ex_to_numeric(coeff).compare(numONE())==0);
35 bool is_equal(expair const & other) const
37 return (rest.is_equal(other.rest) && coeff.is_equal(other.coeff));
39 bool is_less(expair const & other) const
41 return (rest.compare(other.rest)<0) ||
42 (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
44 int compare(expair const & other) const
46 int cmpval=rest.compare(other.rest);
47 if (cmpval!=0) return cmpval;
48 cmpval=coeff.compare(other.coeff);
52 bool is_less_old2(expair const & other) const
55 bool this_numeric_with_coeff_1=is_numeric_with_coeff_1();
56 bool other_numeric_with_coeff_1=other.is_numeric_with_coeff_1();
57 if (this_numeric_with_coeff_1) {
58 if (other_numeric_with_coeff_1) {
59 // both have coeff 1: compare rests
60 return rest.compare(other.rest)<0;
62 // only this has coeff 1: >
64 } else if (other_numeric_with_coeff_1) {
65 // only other has coeff 1: <
68 return (rest.compare(other.rest)<0) ||
69 (!(other.rest.compare(rest)<0) &&
70 (coeff.compare(other.coeff)<0));
72 if (is_ex_exactly_of_type(rest,numeric) &&
73 is_ex_exactly_of_type(other.rest,numeric)) {
74 if (ex_to_numeric(coeff).compare(numONE())==0) {
75 if (ex_to_numeric(other.coeff).compare(numONE())==0) {
76 // both have coeff 1: compare rests
77 return rest.compare(other.rest)<0;
79 // only this has coeff 1: >
81 } else if (ex_to_numeric(other.coeff).compare(numONE())==0) {
82 // only other has coeff 1: <
85 // neither has coeff 1: usual compare
87 return (rest.compare(other.rest)<0) ||
88 (!(other.rest.compare(rest)<0) &&
89 (coeff.compare(other.coeff)<0));
91 int compare_old2(expair const & other) const
93 if (is_ex_exactly_of_type(rest,numeric) &&
94 is_ex_exactly_of_type(other.rest,numeric)) {
95 if (ex_to_numeric(coeff).compare(numONE())==0) {
96 if (ex_to_numeric(other.coeff).compare(numONE())==0) {
97 // both have coeff 1: compare rests
98 return rest.compare(other.rest);
100 // only this has coeff 1: >
102 } else if (ex_to_numeric(other.coeff).compare(numONE())==0) {
103 // only other has coeff 1: <
106 // neither has coeff 1: usual compare
109 bool this_numeric_with_coeff_1=is_numeric_with_coeff_1();
110 bool other_numeric_with_coeff_1=other.is_numeric_with_coeff_1();
111 if (this_numeric_with_coeff_1) {
112 if (other_numeric_with_coeff_1) {
113 // both have coeff 1: compare rests
114 return rest.compare(other.rest);
116 // only this has coeff 1: >
118 } else if (other_numeric_with_coeff_1) {
119 // only other has coeff 1: <
121 // neither has coeff 1: usual compare
124 int cmpval=rest.compare(other.rest);
125 if (cmpval!=0) return cmpval;
126 return coeff.compare(other.coeff);
128 bool is_less_old(expair const & other) const
130 return (rest.compare(other.rest)<0) ||
131 (!(other.rest.compare(rest)<0) && (coeff.compare(other.coeff)<0));
133 int compare_old(expair const & other) const
135 int cmpval=rest.compare(other.rest);
136 if (cmpval!=0) return cmpval;
137 cmpval=coeff.compare(other.coeff);
141 void printraw(ostream & os) const
157 bool operator()(expair const & lh, expair const & rh) const
159 return lh.is_less(rh);
163 class expair_is_less_old
166 bool operator()(expair const & lh, expair const & rh) const
168 return lh.is_less_old(rh);