Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
107 lines (102 loc) · 4.14 KB

File metadata and controls

107 lines (102 loc) · 4.14 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#include <symengine/add.h>
#include <symengine/pow.h>
#include <symengine/rings.h>
#include <symengine/monomials.h>
#include <symengine/symengine_exception.h>
namespace SymEngine
{
void expr2poly(const RCP<const Basic> &p, umap_basic_num &syms, umap_vec_mpz &P)
{
if (is_a<Add>(*p)) {
auto n = syms.size();
const umap_basic_num &d = down_cast<const Add &>(*p).get_dict();
vec_int exp;
integer_class coef;
for (const auto &p : d) {
if (not is_a<Integer>(*p.second))
throw NotImplementedError("Not Implemented");
coef = down_cast<const Integer &>(*p.second).as_integer_class();
exp.assign(n, 0); // Initialize to [0]*n
if (is_a<Mul>(*p.first)) {
const map_basic_basic &term
= down_cast<const Mul &>(*p.first).get_dict();
for (const auto &q : term) {
RCP<const Basic> sym = q.first;
if (not is_a<Integer>(*syms.at(sym)))
throw NotImplementedError("Not Implemented");
int i = numeric_cast<int>(
down_cast<const Integer &>(*syms.at(sym)).as_int());
if (is_a<Integer>(*q.second)) {
exp[i] = numeric_cast<int>(
down_cast<const Integer &>(*q.second).as_int());
} else {
throw SymEngineException(
"Cannot convert symbolic exponents to sparse "
"polynomials with integer exponents.");
}
}
} else if (is_a<Pow>(*p.first)) {
RCP<const Basic> sym
= down_cast<const Pow &>(*p.first).get_base();
RCP<const Basic> exp_
= down_cast<const Pow &>(*p.first).get_exp();
if (not is_a<Integer>(*syms.at(sym)))
throw NotImplementedError("Not Implemented");
int i = numeric_cast<int>(
down_cast<const Integer &>(*syms.at(sym)).as_int());
if (not is_a<Integer>(*exp_))
throw NotImplementedError("Not Implemented");
exp[i] = numeric_cast<int>(
down_cast<const Integer &>(*exp_).as_int());
} else if (is_a<Symbol>(*p.first)) {
RCP<const Basic> sym = p.first;
if (not is_a<Integer>(*syms.at(sym)))
throw NotImplementedError("Not Implemented");
int i = numeric_cast<int>(
down_cast<const Integer &>(*syms.at(sym)).as_int());
exp[i] = 1;
} else {
throw NotImplementedError("Not Implemented");
}
P[exp] = coef;
}
} else {
throw NotImplementedError("Not Implemented");
}
}
void poly_mul(const umap_vec_mpz &A, const umap_vec_mpz &B, umap_vec_mpz &C)
{
vec_int exp;
auto n = A.begin()->first.size();
exp.assign(n, 0); // Initialize to [0]*n
/*
std::cout << "A: " << A.load_factor() << " " << A.bucket_count() << " " <<
A.size() << " "
<< A.max_bucket_count() << std::endl;
std::cout << "B: " << B.load_factor() << " " << B.bucket_count() << " " <<
B.size() << " "
<< B.max_bucket_count() << std::endl;
std::cout << "C: " << C.load_factor() << " " << C.bucket_count() << " " <<
C.size() << " "
<< C.max_bucket_count() << std::endl;
*/
for (const auto &a : A) {
for (const auto &b : B) {
monomial_mul(a.first, b.first, exp);
mp_addmul(C[exp], a.second, b.second);
}
}
/*
std::cout << "C: " << C.load_factor() << " " << C.bucket_count() << " " <<
C.size() << " "
<< C.max_bucket_count() << std::endl;
for (const std::size_t n=0; n < C.bucket_count(); n++) {
std::cout << n << ": " << C.bucket_size(n) << "|";
for (auto it = C.begin(n); it != C.end(n); ++it)
std::cout << " " << it->first << myhash2(it->first) %
C.bucket_count();
std::cout << std::endl;
}
*/
}
} // namespace SymEngine
Morty Proxy This is a proxified and sanitized view of the page, visit original site.