GiNaC 1.8.10
expair.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2026 Johannes Gutenberg University Mainz, Germany
7 *
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.
12 *
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.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef GINAC_EXPAIR_H
23#define GINAC_EXPAIR_H
24
25#include "ex.h"
26#include "numeric.h"
27#include "print.h"
28
29namespace GiNaC {
30
36class expair
37{
38public:
39 expair() : rest(0), coeff(1) { }
40
42 expair(const ex & r, const ex & c) : rest(r), coeff(c)
43 {
44 GINAC_ASSERT(is_exactly_a<numeric>(coeff));
45 }
46
48 bool is_equal(const expair & other) const
49 {
50 return (rest.is_equal(other.rest) && coeff.is_equal(other.coeff));
51 }
52
54 bool is_less(const expair & other) const
55 {
56 int restcmp = rest.compare(other.rest);
57 return ((restcmp<0) ||
58 (!(restcmp>0) && (coeff.compare(other.coeff)<0)));
59 }
60
62 int compare(const expair & other) const
63 {
64 int restcmp = rest.compare(other.rest);
65 if (restcmp!=0)
66 return restcmp;
67 else
68 return coeff.compare(other.coeff);
69 }
70
71 void print(std::ostream & os) const;
72
75 {
76 GINAC_ASSERT(is_exactly_a<numeric>(coeff));
77 return (is_exactly_a<numeric>(rest) && (coeff.is_equal(1)));
78 }
79
81 void swap(expair & other)
82 {
83 rest.swap(other.rest);
84 coeff.swap(other.coeff);
85 }
86
87 const expair conjugate() const;
88
91};
92
95 bool operator()(const expair &lh, const expair &rh) const { return lh.is_less(rh); }
96};
97
103 bool operator()(const expair &lh, const expair &rh) const { return (lh.rest.compare(rh.rest)<0); }
104};
105
107 void operator()(expair &lh, expair &rh) const { lh.swap(rh); }
108};
109
110inline void swap(expair & e1, expair & e2)
111{ e1.swap(e2); }
112
113} // namespace GiNaC
114
115#endif // ndef GINAC_EXPAIR_H
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
Definition assertion.h:32
Lightweight wrapper for GiNaC's symbolic objects.
Definition ex.h:72
bool is_equal(const ex &other) const
Definition ex.h:345
void swap(ex &other) noexcept
Efficiently swap the contents of two expressions.
Definition ex.h:104
int compare(const ex &other) const
Definition ex.h:322
A pair of expressions.
Definition expair.h:37
int compare(const expair &other) const
Member-wise check for canonical ordering.
Definition expair.h:62
bool is_canonical_numeric() const
True if this is of the form (numeric,ex(1)).
Definition expair.h:74
void swap(expair &other)
Swap contents with other expair.
Definition expair.h:81
ex rest
first member of pair, an arbitrary expression
Definition expair.h:89
const expair conjugate() const
Definition expair.cpp:35
ex coeff
second member of pair, must be numeric
Definition expair.h:90
expair(const ex &r, const ex &c)
Construct an expair from two ex.
Definition expair.h:42
void print(std::ostream &os) const
Definition expair.cpp:27
bool is_less(const expair &other) const
Member-wise check for canonical ordering lessness.
Definition expair.h:54
bool is_equal(const expair &other) const
Member-wise check for canonical ordering equality.
Definition expair.h:48
Interface to GiNaC's light-weight expression handles.
size_t c
Definition factor.cpp:756
size_t r
Definition factor.cpp:756
Definition add.cpp:35
void swap(ex &e1, ex &e2)
Definition ex.h:838
Makes the interface to the underlying bignum package available.
Definition of helper classes for expression output.
Function object for insertion into third argument of STL's sort() etc.
Definition expair.h:94
bool operator()(const expair &lh, const expair &rh) const
Definition expair.h:95
Function object not caring about the numerical coefficients for insertion into third argument of STL'...
Definition expair.h:102
bool operator()(const expair &lh, const expair &rh) const
Definition expair.h:103
void operator()(expair &lh, expair &rh) const
Definition expair.h:107

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.