GiNaC  1.8.0
relational.h
Go to the documentation of this file.
1 
5 /*
6  * GiNaC Copyright (C) 1999-2020 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_RELATIONAL_H
24 #define GINAC_RELATIONAL_H
25 
26 #include "basic.h"
27 #include "ex.h"
28 #include "archive.h"
29 
30 namespace GiNaC {
31 
34 class relational : public basic
35 {
37 
38 // types
39 public:
40  enum operators {
47  };
48 
49  // other constructors
50 public:
51  relational(const ex & lhs, const ex & rhs, operators oper=equal);
52 
53  // functions overriding virtual functions from base classes
54 public:
55  unsigned precedence() const override {return 20;}
56  bool info(unsigned inf) const override;
57  size_t nops() const override;
58  ex op(size_t i) const override;
59  ex map(map_function & f) const override;
60  ex subs(const exmap & m, unsigned options = 0) const override;
61 
63  void archive(archive_node& n) const override;
65  void read_archive(const archive_node& n, lst& syms) override;
66 protected:
67  ex eval_ncmul(const exvector & v) const override;
68  bool match_same_type(const basic & other) const override;
69  unsigned return_type() const override;
70  return_type_t return_type_tinfo() const override;
71  unsigned calchash() const override;
72 
73  // new virtual functions which can be overridden by derived classes
74 protected:
75  void do_print(const print_context & c, unsigned level) const;
76  void do_print_python_repr(const print_python_repr & c, unsigned level) const;
77 
78 public:
79  ex lhs() const { return lh; }
80  ex rhs() const { return rh; }
81 
82  // non-virtual functions in this class
83 private:
84  // For conversions to Boolean, as would be used in an if conditional,
85  // implicit conversions from bool to int have a large number of
86  // undesirable side effects. The following safe_bool type enables
87  // use of relational objects in conditionals without those side effects
89  void nonnull() {};
90  };
91 
92  typedef void (safe_bool_helper::*safe_bool)();
93 
94  safe_bool make_safe_bool(bool) const;
95 
96 public:
97  operator safe_bool() const;
98  safe_bool operator!() const;
99 
100 // member variables
101 
102 protected:
106 };
108 
109 // utility functions
110 
111 // inlined functions for efficiency
113 {
114  return make_safe_bool(!static_cast<bool>(*this));
115 }
116 
117 } // namespace GiNaC
118 
119 #endif // ndef GINAC_RELATIONAL_H
size_t nops() const override
Number of operands/members.
Definition: relational.cpp:155
unsigned return_type() const override
Definition: relational.cpp:238
exset syms
Definition: factor.cpp:2434
unsigned calchash() const override
Compute the hash value of an object and if it makes sense to store it in the objects status_flags...
Definition: relational.cpp:250
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
Definition: relational.cpp:59
Definition: add.cpp:38
This class holds a relation consisting of two expressions and a logical relation between them...
Definition: relational.h:34
Archiving of GiNaC expressions.
This class is the ABC (abstract base class) of GiNaC&#39;s class hierarchy.
Definition: basic.h:104
Context for python-parsable output.
Definition: print.h:138
ex eval_ncmul(const exvector &v) const override
Definition: relational.cpp:190
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: relational.cpp:179
safe_bool make_safe_bool(bool) const
Definition: relational.cpp:299
void(safe_bool_helper::* safe_bool)()
Definition: relational.h:92
relational(const ex &lhs, const ex &rhs, operators oper=equal)
Definition: relational.cpp:52
unsigned options
Definition: factor.cpp:2480
mvec m
Definition: factor.cpp:771
To distinguish between different kinds of non-commutative objects.
Definition: registrar.h:43
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition: relational.h:55
std::vector< ex > exvector
Definition: basic.h:46
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
safe_bool operator!() const
Definition: relational.h:112
Function object for map().
Definition: basic.h:85
size_t n
Definition: factor.cpp:1463
Interface to GiNaC&#39;s light-weight expression handles.
Base class for print_contexts.
Definition: print.h:102
void archive(archive_node &n) const override
Save (a.k.a.
Definition: relational.cpp:71
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
Definition: relational.cpp:230
Interface to GiNaC&#39;s ABC.
ex rhs() const
Definition: relational.h:80
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Definition: relational.cpp:123
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:48
Lightweight wrapper for GiNaC&#39;s symbolic objects.
Definition: ex.h:72
ex op(size_t i) const override
Return operand/member at position i.
Definition: relational.cpp:160
void do_print(const print_context &c, unsigned level) const
Definition: relational.cpp:112
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
GINAC_DECLARE_UNARCHIVER(add)
size_t c
Definition: factor.cpp:770
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only...
Definition: relational.cpp:167
ex lhs() const
Definition: relational.h:79
bool info(unsigned inf) const override
Information about the object.
Definition: relational.cpp:134
return_type_t return_type_tinfo() const override
Definition: relational.cpp:244

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