44#include <initializer_list>
48#include <unordered_map>
75 std::shared_ptr<Data> data_;
315 using Map = std::unordered_map<Symbol, Assumption, SymEngine::RCPBasicHash, SymEngine::RCPBasicKeyEq>;
323 class const_iterator {
326 Map::const_iterator own_;
327 Map::const_iterator base_;
328 bool in_base_ =
false;
331 : owner_(owner), own_(own), base_(base), in_base_(in_base) {
334 void skip_shadowed() {
335 while (base_ != owner_->base_->end() && owner_->own_.find(base_->first) != owner_->own_.end()) {
350 return in_base_ ? *base_ : *own_;
353 return in_base_ ? &*base_ : &*own_;
363 if (own_ == owner_->own_.end() && owner_->base_) {
365 base_ = owner_->base_->begin();
378 if (in_base_ != other.in_base_) {
381 return in_base_ ? base_ == other.base_ : own_ == other.own_;
384 return !(*
this == other);
389 Assumptions(std::initializer_list<value_type> entries) : own_(entries) {
399 result.base_ = std::move(base);
400 if (result.base_ && result.base_->empty()) {
401 result.base_.reset();
407 return own_.size() + (base_ ? base_->size() : 0) - shadowed_;
420 if (own_.empty() && base_) {
428 return base_ ?
const_iterator(
this, own_.end(), base_->end(),
true)
448 auto own = own_.find(
symbol);
449 if (own != own_.end()) {
453 auto base = base_->find(
symbol);
454 if (base != base_->end()) {
463 auto own = own_.find(
symbol);
464 if (own != own_.end() || !base_) {
467 auto base = base_->find(
symbol);
468 if (base == base_->end()) {
471 return promote(*base);
475 return own_.contains(
symbol) || (base_ && base_->contains(
symbol));
482 auto own = own_.find(
symbol);
483 if (own != own_.end()) {
487 auto base = base_->find(
symbol);
488 if (base != base_->end()) {
492 throw std::out_of_range(
"Assumptions::at: no assumption for " +
symbol->get_name());
497 if (it == own_.end()) {
498 throw std::out_of_range(
"Assumptions::at: no assumption for " +
symbol->get_name());
505 if (it != own_.end()) {
514 auto present =
find(entry.first);
515 if (present != own_.end()) {
516 return {present,
false};
518 return own_.insert(entry);
521 auto present =
find(entry.first);
522 if (present != own_.end()) {
523 return {present,
false};
525 return own_.insert(std::move(entry));
527 template<
typename InputIt>
528 void insert(InputIt first, InputIt last) {
529 for (; first != last; ++first) {
533 template<
typename... Args>
534 std::pair<iterator, bool>
emplace(Args&&... args) {
537 template<
typename... Args>
540 if (present != own_.end()) {
541 return {present,
false};
543 return own_.try_emplace(
symbol, std::forward<Args>(args)...);
548 if (present != own_.end()) {
549 present->second = std::forward<M>(value);
550 return {present,
false};
552 return own_.insert_or_assign(
symbol, std::forward<M>(value));
558 return own_.extract(
symbol);
560 Map::insert_return_type
insert(Map::node_type&& node) {
562 return own_.insert(std::move(node));
567 return own_.erase(
symbol);
571 return own_.erase(position);
576 std::shared_ptr<const Map> base_;
582 return own_.insert(base_entry).first;
589 for (
auto& entry : *base_) {
Represents assumptions about a symbol's properties and behavior.
Definition assumptions.h:61
Assumption & operator=(const Assumption &a)
Assignment operator.
Assumption(const Assumption &a)
Copy constructor.
const ExpressionSet & upper_bounds() const
Gets all upper bound constraints.
const Expression tight_upper_bound() const
Gets the tight upper bound.
ReplaceResult
Definition assumptions.h:297
@ IdSame
Definition assumptions.h:297
@ IdChanged
Definition assumptions.h:297
bool contains_constraint(const Expression c)
Checks if a specific constraint is present.
bool contains_lower_bound(const Expression lb)
Checks if a specific lower bound exists.
void tight_lower_bound(const Expression tight_lb)
Sets the tight lower bound.
bool contains_upper_bound(const Expression ub)
Checks if a specific upper bound exists.
const Expression map() const
Gets the evolution map for this symbol.
void constant(bool constant)
Sets whether the symbol is constant.
void tight_upper_bound(const Expression tight_ub)
Sets the tight upper bound.
void add_upper_bound(const Expression ub)
Adds an upper bound constraint.
const Symbol symbol() const
Gets the symbol this assumption is for.
static Assumption create(const Symbol symbol, const types::IType &type)
Creates an assumption with bounds derived from a type.
void map(const Expression map)
Sets the evolution map for this symbol.
ReplaceResult replace(const symbolic::ExpressionMapping &replacements)
bool remove_upper_bound(const Expression ub)
Removes an upper bound constraint.
const Expression tight_lower_bound() const
Gets the tight lower bound.
bool remove_lower_bound(const Expression lb)
Removes a lower bound constraint.
const ExpressionSet & lower_bounds() const
Gets all lower bound constraints.
void add_lower_bound(const Expression lb)
Adds a lower bound constraint.
Assumption()
Default constructor creating an empty assumption.
const ExpressionSet & constraints() const
Gets the constraints registered on this symbol.
bool remove_constraint(const Expression c)
Removes a constraint.
bool constant() const
Checks if the symbol is constant.
void add_constraint(const Expression c)
Adds a constraint involving this symbol.
Assumption(const Symbol symbol)
Constructs an assumption for a specific symbol.
Visits the own entries, then the base's entries the own ones do not shadow.
Definition assumptions.h:323
std::ptrdiff_t difference_type
Definition assumptions.h:343
const_iterator operator++(int)
Definition assumptions.h:371
pointer operator->() const
Definition assumptions.h:352
bool operator==(const const_iterator &other) const
Definition assumptions.h:377
bool operator!=(const const_iterator &other) const
Definition assumptions.h:383
const value_type * pointer
Definition assumptions.h:344
std::forward_iterator_tag iterator_category
Definition assumptions.h:341
const value_type & reference
Definition assumptions.h:345
const_iterator & operator++()
Definition assumptions.h:356
reference operator*() const
Definition assumptions.h:349
friend class Assumptions
Definition assumptions.h:324
Assumptions::value_type value_type
Definition assumptions.h:342
Map from symbols to their assumptions.
Definition assumptions.h:313
iterator end()
Definition assumptions.h:443
void clear()
Definition assumptions.h:413
Map::value_type value_type
Definition assumptions.h:318
const Assumption & at(const Symbol &symbol) const
Definition assumptions.h:481
static Assumptions over(std::shared_ptr< const Map > base)
An instance holding no entries of its own over base, which it shares.
Definition assumptions.h:397
size_type size() const
Definition assumptions.h:406
const_iterator end() const
Definition assumptions.h:427
void insert(InputIt first, InputIt last)
Definition assumptions.h:528
std::pair< iterator, bool > try_emplace(const Symbol &symbol, Args &&... args)
Definition assumptions.h:538
Assumption mapped_type
Definition assumptions.h:317
Map::node_type extract(const Symbol &symbol)
Node handles, as for renaming an entry's symbol, work on own entries: the base is copied in first.
Definition assumptions.h:556
const_iterator cend() const
Definition assumptions.h:434
size_type count(const Symbol &symbol) const
Definition assumptions.h:477
Symbol key_type
Definition assumptions.h:316
Assumption & at(const Symbol &symbol)
Definition assumptions.h:495
const_iterator begin() const
Definition assumptions.h:419
std::pair< iterator, bool > insert_or_assign(const Symbol &symbol, M &&value)
Definition assumptions.h:546
Map::insert_return_type insert(Map::node_type &&node)
Definition assumptions.h:560
std::pair< iterator, bool > insert(value_type &&entry)
Definition assumptions.h:520
iterator find(const Symbol &symbol)
A mutable entry, copied from the base first if only the base holds it.
Definition assumptions.h:462
Assumption & operator[](const Symbol &symbol)
Definition assumptions.h:503
Assumptions(Map &&entries)
Definition assumptions.h:393
std::unordered_map< Symbol, Assumption, SymEngine::RCPBasicHash, SymEngine::RCPBasicKeyEq > Map
Definition assumptions.h:315
bool empty() const
Definition assumptions.h:409
std::pair< iterator, bool > emplace(Args &&... args)
Definition assumptions.h:534
const_iterator find(const Symbol &symbol) const
Definition assumptions.h:447
iterator erase(iterator position)
Definition assumptions.h:569
std::pair< iterator, bool > insert(const value_type &entry)
Inserts entry unless its symbol has an entry, here or in the base; true if it did.
Definition assumptions.h:513
const_iterator cbegin() const
Definition assumptions.h:431
size_type erase(const Symbol &symbol)
Definition assumptions.h:565
bool contains(const Symbol &symbol) const
Definition assumptions.h:474
Map::iterator iterator
Definition assumptions.h:320
iterator begin()
Mutable iteration: the base is copied in first. The end is the own entries', which mutable finds retu...
Definition assumptions.h:439
Assumptions(std::initializer_list< value_type > entries)
Definition assumptions.h:389
std::size_t size_type
Definition assumptions.h:319
Assumptions(const Map &entries)
Definition assumptions.h:391
Abstract base interface for all types in the sdfglib type system.
Definition type.h:625
Symbol symbol(const std::string &name)
Creates a symbolic variable with the given name.
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
SymEngine::RCP< const SymEngine::Symbol > Symbol
Reference-counted pointer to a SymEngine Symbol.
Definition symbolic.h:71
std::set< Expression, SymEngine::RCPBasicKeyLess > ExpressionSet
Ordered set of expressions.
Definition symbolic.h:104
SymEngine::map_basic_basic ExpressionMapping
Definition symbolic.h:109
Definition assumptions.h:55
bool substitute(Assumptions &assumptions, const symbolic::ExpressionMapping &replacements)
Symbolic system for integer-based symbol analysis.
Core type system definitions for sdfglib.