GiNaC 1.8.7
expair.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2023 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, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef GINAC_EXPAIR_H
24#define GINAC_EXPAIR_H
25
26#include "ex.h"
27#include "numeric.h"
28#include "print.h"
29
30namespace GiNaC {
31
37class expair
38{
39public:
40 expair() : rest(0), coeff(1) { }
41
43 expair(const ex & r, const ex & c) : rest(r), coeff(c)
44 {
45 GINAC_ASSERT(is_exactly_a<numeric>(coeff));
46 }
47
49 bool is_equal(const expair & other) const
50 {
51 return (rest.is_equal(other.rest) && coeff.is_equal(other.coeff));
52 }
53
55 bool is_less(const expair & other) const
56 {
57 int restcmp = rest.compare(other.rest);
58 return ((restcmp<0) ||
59 (!(restcmp>0) && (coeff.compare(other.coeff)<0)));
60 }
61
63 int compare(const expair & other) const
64 {
65 int restcmp = rest.compare(other.rest);
66 if (restcmp!=0)
67 return restcmp;
68 else
69 return coeff.compare(other.coeff);
70 }
71
72 void print(std::ostream & os) const;
73
76 {
77 GINAC_ASSERT(is_exactly_a<numeric>(coeff));
78 return (is_exactly_a<numeric>(rest) && (coeff.is_equal(1)));
79 }
80
82 void swap(expair & other)
83 {
84 rest.swap(other.rest);
85 coeff.swap(other.coeff);
86 }
87
88 const expair conjugate() const;
89
92};
93
96 bool operator()(const expair &lh, const expair &rh) const { return lh.is_less(rh); }
97};
98
104 bool operator()(const expair &lh, const expair &rh) const { return (lh.rest.compare(rh.rest)<0); }
105};
106
108 void operator()(expair &lh, expair &rh) const { lh.swap(rh); }
109};
110
111inline void swap(expair & e1, expair & e2)
112{ e1.swap(e2); }
113
114} // namespace GiNaC
115
116#endif // ndef GINAC_EXPAIR_H
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
Definition: assertion.h:33
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:38
int compare(const expair &other) const
Member-wise check for canonical ordering.
Definition: expair.h:63
bool is_canonical_numeric() const
True if this is of the form (numeric,ex(1)).
Definition: expair.h:75
void swap(expair &other)
Swap contents with other expair.
Definition: expair.h:82
ex rest
first member of pair, an arbitrary expression
Definition: expair.h:90
const expair conjugate() const
Definition: expair.cpp:38
ex coeff
second member of pair, must be numeric
Definition: expair.h:91
expair(const ex &r, const ex &c)
Construct an expair from two ex.
Definition: expair.h:43
void print(std::ostream &os) const
Definition: expair.cpp:30
bool is_less(const expair &other) const
Member-wise check for canonical ordering lessness.
Definition: expair.h:55
bool is_equal(const expair &other) const
Member-wise check for canonical ordering equality.
Definition: expair.h:49
Interface to GiNaC's light-weight expression handles.
size_t c
Definition: factor.cpp:757
size_t r
Definition: factor.cpp:757
Definition: add.cpp:38
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:95
bool operator()(const expair &lh, const expair &rh) const
Definition: expair.h:96
Function object not caring about the numerical coefficients for insertion into third argument of STL'...
Definition: expair.h:103
bool operator()(const expair &lh, const expair &rh) const
Definition: expair.h:104
void operator()(expair &lh, expair &rh) const
Definition: expair.h:108

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