Loading...
Searching...
No Matches
SymEngine::BasicToMPolyBase< P, V > Class Template Reference
+ Inheritance diagram for SymEngine::BasicToMPolyBase< P, V >:
+ Collaboration diagram for SymEngine::BasicToMPolyBase< P, V >:

Public Types

using Dict = typename P::container_type
 
using Vec = typename Dict::vec_type
 

Public Member Functions

 BasicToMPolyBase (const set_basic &gens_)
 
Dict apply (const Basic &b)
 
void dict_set (Vec pow, const Basic &x)
 
void bvisit (const Pow &x)
 
void bvisit (const Add &x)
 
void bvisit (const Mul &x)
 
void bvisit (const Integer &x)
 
void bvisit (const Basic &x)
 

Data Fields

Dict dict
 
set_basic gens
 
std::unordered_map< RCP< const Basic >, vec_basic, RCPBasicHash, RCPBasicKeyEqgens_pow
 
umap_basic_uint gens_map
 

Detailed Description

template<typename P, typename V>
class SymEngine::BasicToMPolyBase< P, V >

Definition at line 326 of file basic_conversions.h.

Member Typedef Documentation

◆ Dict

template<typename P , typename V >
using SymEngine::BasicToMPolyBase< P, V >::Dict = typename P::container_type

Definition at line 329 of file basic_conversions.h.

◆ Vec

template<typename P , typename V >
using SymEngine::BasicToMPolyBase< P, V >::Vec = typename Dict::vec_type

Definition at line 330 of file basic_conversions.h.

Constructor & Destructor Documentation

◆ BasicToMPolyBase()

template<typename P , typename V >
SymEngine::BasicToMPolyBase< P, V >::BasicToMPolyBase ( const set_basic gens_)
inline

Definition at line 337 of file basic_conversions.h.

338 {
339 gens = gens_;
340 dict.vec_size = static_cast<int>(gens.size());
341
342 RCP<const Basic> genpow, genbase;
343 unsigned int i = 0;
344
345 for (auto it : gens) {
346 genpow = one;
347 genbase = it;
348 if (is_a<const Pow>(*it)) {
349 genpow = down_cast<const Pow &>(*it).get_exp();
350 genbase = down_cast<const Pow &>(*it).get_base();
351 }
352 auto ite = gens_pow.find(genbase);
353 if (ite == gens_pow.end())
354 gens_pow[genbase] = {genpow};
355 else
356 gens_pow[genbase].push_back(genpow);
357 gens_map[it] = i++;
358 }
359 }
T size(T... args)

Member Function Documentation

◆ apply()

template<typename P , typename V >
Dict SymEngine::BasicToMPolyBase< P, V >::apply ( const Basic b)
inline

Definition at line 361 of file basic_conversions.h.

362 {
363 b.accept(*this);
364 return std::move(dict);
365 }
T move(T... args)

◆ bvisit() [1/5]

template<typename P , typename V >
void SymEngine::BasicToMPolyBase< P, V >::bvisit ( const Add x)
inline

Definition at line 430 of file basic_conversions.h.

431 {
432 Dict res = apply(*x.get_coef());
433 for (auto const &it : x.get_dict())
434 res += apply(*it.first) * apply(*it.second);
435 dict = std::move(res);
436 }

◆ bvisit() [2/5]

template<typename P , typename V >
void SymEngine::BasicToMPolyBase< P, V >::bvisit ( const Basic x)
inline

Definition at line 453 of file basic_conversions.h.

454 {
455 RCP<const Basic> powr;
456 Vec zero_v(gens.size(), 0);
457
458 auto it = gens_pow.find(x.rcp_from_this());
459 if (it != gens_pow.end()) {
460
461 for (auto pows : it->second) {
462 powr = div(one, pows);
463 if (is_a<const Integer>(*powr)) {
464 int i = numeric_cast<int>(
465 down_cast<const Integer &>(*powr).as_int());
466 if (i > 0) {
467 // can be optimized
468 zero_v[gens_map[pow(it->first, pows)]] = i;
469 dict = P::container_from_dict(
470 gens, {{zero_v, typename P::coef_type(1)}});
471 return;
472 }
473 }
474 }
475 }
476
477 dict_set(zero_v, x);
478 }
RCP< const Basic > div(const RCP< const Basic > &a, const RCP< const Basic > &b)
Division.
Definition: mul.cpp:431
T pow(T... args)

◆ bvisit() [3/5]

template<typename P , typename V >
void SymEngine::BasicToMPolyBase< P, V >::bvisit ( const Integer x)
inline

Definition at line 446 of file basic_conversions.h.

447 {
448 integer_class i = x.as_integer_class();
449 Vec zero_v(gens.size(), 0);
450 dict = P::container_from_dict(gens, {{zero_v, i}});
451 }

◆ bvisit() [4/5]

template<typename P , typename V >
void SymEngine::BasicToMPolyBase< P, V >::bvisit ( const Mul x)
inline

Definition at line 438 of file basic_conversions.h.

439 {
440 Dict res = apply(*x.get_coef());
441 for (auto const &it : x.get_dict())
442 res *= apply(*pow(it.first, it.second));
443 dict = std::move(res);
444 }

◆ bvisit() [5/5]

template<typename P , typename V >
void SymEngine::BasicToMPolyBase< P, V >::bvisit ( const Pow x)
inline

Definition at line 372 of file basic_conversions.h.

373 {
374 if (is_a<const Integer>(*x.get_exp())) {
375 int i = numeric_cast<int>(
376 down_cast<const Integer &>(*x.get_exp()).as_int());
377 if (i > 0) {
378 dict = Dict::pow(_basic_to_mpoly<P>(x.get_base(), gens), i);
379 return;
380 }
381 }
382
383 Vec zero_v(gens.size(), 0);
384 RCP<const Basic> coef = one, tmp;
385 RCP<const Integer> i;
386 bool found;
387 auto ite = gens_pow.find(x.get_base());
388
389 if (ite != gens_pow.end()) {
390
391 set_basic expos;
392
393 if (is_a<const Add>(*x.get_exp())) {
394 RCP<const Add> addx = rcp_static_cast<const Add>(x.get_exp());
395 for (auto const &it : addx->get_dict())
396 expos.insert(mul(it.first, it.second));
397 if (not addx->get_coef()->is_zero())
398 expos.insert(addx->get_coef());
399 } else {
400 expos.insert(x.get_exp());
401 }
402
403 for (auto const &it : expos) {
404
405 found = false;
406
407 for (auto powr : ite->second) {
408 tmp = div(it, powr);
409 if (is_a<const Integer>(*tmp)) {
410 i = rcp_static_cast<const Integer>(tmp);
411 if (i->is_positive()) {
412 zero_v[gens_map[pow(ite->first, powr)]]
413 = static_cast<int>(i->as_int());
414 found = true;
415 break;
416 }
417 }
418 }
419
420 if (not found)
421 coef = mul(coef, pow(ite->first, it));
422 }
423 dict_set(zero_v, *coef);
424
425 } else {
426 dict_set(zero_v, x);
427 }
428 }
RCP< const Basic > mul(const RCP< const Basic > &a, const RCP< const Basic > &b)
Multiplication.
Definition: mul.cpp:352

◆ dict_set()

template<typename P , typename V >
void SymEngine::BasicToMPolyBase< P, V >::dict_set ( Vec  pow,
const Basic x 
)
inline

Definition at line 367 of file basic_conversions.h.

368 {
369 down_cast<V *>(this)->dict_set(pow, x);
370 }

Field Documentation

◆ dict

template<typename P , typename V >
Dict SymEngine::BasicToMPolyBase< P, V >::dict

Definition at line 331 of file basic_conversions.h.

◆ gens

template<typename P , typename V >
set_basic SymEngine::BasicToMPolyBase< P, V >::gens

Definition at line 332 of file basic_conversions.h.

◆ gens_map

template<typename P , typename V >
umap_basic_uint SymEngine::BasicToMPolyBase< P, V >::gens_map

Definition at line 335 of file basic_conversions.h.

◆ gens_pow

template<typename P , typename V >
std::unordered_map<RCP<const Basic>, vec_basic, RCPBasicHash, RCPBasicKeyEq> SymEngine::BasicToMPolyBase< P, V >::gens_pow

Definition at line 334 of file basic_conversions.h.


The documentation for this class was generated from the following file: