Class Power

Inheritance Relationships

Base Type

Class Documentation

class Power : public sequant::Expr

Represents base^exponent where base is a scalar (Constant or Variable) and exponent is a rational number.

Public Types

using exponent_type = rational

Public Functions

Power() = delete
virtual ~Power() = default
Power(const Power&) = default
Power(Power&&) = default
Power &operator=(const Power&) = default
Power &operator=(Power&&) = default
Power(ExprPtr base, exponent_type exponent)
Parameters:
  • base – [in] the base expression; must be a Constant or Variable.

  • exponent – [in] rational exponent

template<typename L>
inline Power(L &&label, exponent_type exponent)
template<typename V>
inline Power(V &&value, exponent_type exponent)
const ExprPtr &base() const
Returns:

the base expression

const exponent_type &exponent() const
Returns:

the rational exponent

bool conjugated() const

Note

Conjugation is tracked as a flag rather than pushed into the base because, for a fixed branch, conj(base^exponent) and conj(base)^exponent differ on the branch cut. As sets of branches they coincide, and SeQuant treats a Power as a branch chosen consistently, so the two are identified by Power::operator*= and by simplify(); evaluation with the principal branch agrees with this except for bases on the negative real axis.

Returns:

whether this Power has been complex-conjugated via adjoint()

void conjugate()

toggles the conjugation flag

virtual bool is_zero() const override

Note

Construction rejects all undefined 0^n cases; 0^0 is legal and treated as 1.

Returns:

true if the base is zero and the exponent is positive

virtual std::wstring to_latex() const override
Returns:

the string representation of this in the LaTeX format

virtual type_id_type type_id() const override

Computes and returns the derived type identifier

Returns:

the hash value for this Expr

virtual bool is_scalar() const override

Reports if this is a pure scalar (number-like) expression.

Note

This is distinct from is_cnumber()

Warning

this returns false for all leaves by default, hence must be overridden for scalar leaf types.

Returns:

true if this is a scalar

virtual ExprPtr clone() const override
Returns:

a clone of this object, i.e. an object that is equal to this

virtual void adjoint() override

adjoint of Power: flips the conjugation flag.

Power &operator*=(const Expr &that)

Combines exponents when effective bases match:

  • b^e1 *= b^e2 → b^(e1+e2) when this and that share the same Power-level conjugation flag.

  • b^e *= B → b^(e+1) for a bare scalar B equal to this Power’s effective base. For a Variable base the labels must match and the effective conjugation parities align. For a Constant base only the fully unconjugated case combines.

Throws:

Exception – if that is not combinable.

Public Static Functions

static void flatten(ExprPtr &expr)

Attempts to flatten a Power, mutating expr in place. Folds when expr holds a Power and any of:

  • the exponent is 1 (then b^1 = b and conjugate if needed);

  • the exponent is 0 (then b^0 = 1 for any base);

  • the base is the Constant 1 (then 1^k = 1 for any rational k);

  • the base is a Constant and the exponent is an integer, unless the exponent times the bit width of the base, i.e. of the larger of its common denominator and |Re numerator| + |Im numerator| over that denominator, which bounds the width of the value from above, exceeds default_max_folded_bits;

  • the base is the Constant 0 (then 0^k = 0 for the k > 0 the constructor admits);

  • the base is a positive real rational and the value is rational, i.e. its simplest_radical_form() has no root (e.g. 4^{1/2} -> 2, (1/8)^{1/3} -> 1/2, (9/16)^{3/2} -> 27/64). On success, expr is rebound to the folded expression; otherwise it is left unchanged.

static inline constexpr std::string static_type_name(std::type_identity<Power> = {})

Public Static Attributes

static constexpr type_rank_type type_rank = expr_type_rank::power