forked from symengine/symengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdict.cpp
More file actions
125 lines (110 loc) · 2.82 KB
/
Copy pathdict.cpp
File metadata and controls
125 lines (110 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <symengine/expression.h>
namespace SymEngine
{
namespace
{
template <class T>
inline std::ostream &print_map(std::ostream &out, T &d)
{
out << "{";
for (auto p = d.begin(); p != d.end(); p++) {
if (p != d.begin())
out << ", ";
out << (p->first) << ": " << (p->second);
}
out << "}";
return out;
}
template <class T>
inline std::ostream &print_map_rcp(std::ostream &out, T &d)
{
out << "{";
for (auto p = d.begin(); p != d.end(); p++) {
if (p != d.begin())
out << ", ";
out << *(p->first) << ": " << *(p->second);
}
out << "}";
return out;
}
template <class T>
inline std::ostream &print_vec(std::ostream &out, T &d)
{
out << "{";
for (auto p = d.begin(); p != d.end(); p++) {
if (p != d.begin())
out << ", ";
out << *p;
}
out << "}";
return out;
}
template <class T>
inline std::ostream &print_vec_rcp(std::ostream &out, T &d)
{
out << "{";
for (auto p = d.begin(); p != d.end(); p++) {
if (p != d.begin())
out << ", ";
out << **p;
}
out << "}";
return out;
}
} // anonymous namespace
std::ostream &operator<<(std::ostream &out, const SymEngine::umap_basic_num &d)
{
return SymEngine::print_map_rcp(out, d);
}
std::ostream &operator<<(std::ostream &out, const SymEngine::map_basic_num &d)
{
return SymEngine::print_map_rcp(out, d);
}
std::ostream &operator<<(std::ostream &out, const SymEngine::map_basic_basic &d)
{
return SymEngine::print_map_rcp(out, d);
}
std::ostream &operator<<(std::ostream &out,
const SymEngine::umap_basic_basic &d)
{
return SymEngine::print_map_rcp(out, d);
}
std::ostream &operator<<(std::ostream &out, const SymEngine::vec_basic &d)
{
return SymEngine::print_vec_rcp(out, d);
}
std::ostream &operator<<(std::ostream &out, const SymEngine::set_basic &d)
{
return SymEngine::print_vec_rcp(out, d);
}
std::ostream &operator<<(std::ostream &out, const SymEngine::map_int_Expr &d)
{
return SymEngine::print_map(out, d);
}
std::ostream &operator<<(std::ostream &out, const SymEngine::vec_pair &d)
{
return SymEngine::print_map_rcp(out, d);
}
bool vec_basic_eq_perm(const vec_basic &a, const vec_basic &b)
{
// Can't be equal if # of entries differ:
if (a.size() != b.size())
return false;
// Loop over elements in "a"
for (size_t i = 0; i < a.size(); i++) {
// Find the element a[i] in "b"
bool found = false;
for (size_t j = 0; j < a.size(); j++) {
if (eq(*a[i], *b[j])) {
found = true;
break;
}
}
// If not found, then a != b
if (not found)
return false;
}
// If all elements were found, then a == b
return true;
}
} // namespace SymEngine