Class AsyCost

Nested Relationships

Nested Types

Class Documentation

class AsyCost

Represents a symbolic asymptotic cost as a polynomial in the sizes of bases of index spaces. A cost is a sum of terms, each of which is a rational multiplier times a product of basis sizes raised to non-negative integer powers. Bases are identified by IndexBasis, so each basis instance of a space is a symbol of its own; AsyCost orders them using IndexBasis’s own ordering (a space’s own basis orders as the space), prints a space’s own basis by its base_key(), a named basis instance by its name and an unnamed one as base_key()<;N>, and never consults an IndexBasisRegistry.

Examples (with I, A denoting two index spaces):

  • AsyCost({{I, 2}, {A, 4}}) represents $I^2 A^4$.

  • AsyCost({{I, 2}, {A, 4}}, rational{1, 2}) halves the numeric value above when extents are substituted.

Public Types

using ExponentMap = container::map<IndexBasis, std::size_t>
using ExtentMap = container::map<IndexBasis, std::size_t>

Public Functions

AsyCost()

Default construct to zero cost.

explicit AsyCost(ExponentMap exponents, rational prefactor = 1)
Parameters:
  • exponents – Map from basis to its exponent in this term. Zero exponents may be supplied; they are dropped.

  • prefactor – Rational multiplier; defaults to 1.

AsyCost(AsyCost const&) = default
AsyCost(AsyCost&&) = default
AsyCost &operator=(AsyCost const&) = default
AsyCost &operator=(AsyCost&&) = default
double ops(ExtentMap const &extents = {}) const

Substitute each basis in this cost by an extent and evaluate.

Parameters:

extents – Map from basis to extent (size). A basis appearing in this cost but absent from extents falls back to its IndexBasis::extent() (the dimension of its space, or for a named basis instance obtained from the registry the extent it was registered with). Defaults to empty, in which case every basis uses that extent.

Returns:

Numerical value of the cost.

std::wstring to_latex() const
Returns:

A LaTeX rendering of the whole cost: its terms joined by +, most expensive first. The zero cost renders as 0.

std::string text() const
Returns:

A plain-text rendering of the whole cost: its terms joined by +, most expensive first. The zero cost renders as 0.

AsyCost &operator+=(AsyCost const&)
AsyCost &operator-=(AsyCost const&)

Public Static Functions

static AsyCost const &max()
Returns:

The infinitely scaling cost.

static AsyCost const &zero()
Returns:

The zero cost.

Friends

friend AsyCost operator+(AsyCost const &lhs, AsyCost const &rhs)
friend AsyCost operator*(AsyCost const &lhs, rational scale)
friend AsyCost operator*(rational scale, AsyCost const &lhs)
friend bool operator<(AsyCost const &lhs, AsyCost const &rhs)
friend bool operator==(AsyCost const &lhs, AsyCost const &rhs)
friend bool operator<=(AsyCost const &lhs, AsyCost const &rhs)
friend bool operator>=(AsyCost const &lhs, AsyCost const &rhs)