Class Power¶
Defined in File power.hpp
Inheritance Relationships¶
Base Type¶
public sequant::Expr(Class Expr)
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 Functions
-
Power() = delete¶
-
virtual ~Power() = default¶
-
inline Power(ExprPtr base, exponent_type exponent)¶
-
template<typename L>
inline Power(L &&label, exponent_type exponent)¶
-
template<typename V>
inline Power(V &&value, exponent_type exponent)¶
-
inline const exponent_type &exponent() const¶
- Returns:
the rational exponent
-
inline bool conjugated() const¶
Note
Conjugation is tracked as a flag because, in general,
conj(base^exponent) != conj(base)^exponent
-
inline void conjugate()¶
toggles the conjugation flag
-
inline 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
-
inline virtual type_id_type type_id() const override¶
Computes and returns the derived type identifier
See also
Note
this function must be overridden in the derived class
- Returns:
the hash value for this Expr
-
inline 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
-
inline virtual ExprPtr clone() const override¶
Note
- must be overridden in the derived class.
the default implementation throws an exception
- Returns:
a clone of this object, i.e. an object that is equal to
this
-
inline virtual Expr &operator*=(const Expr &that) override¶
Combines exponents when effective bases match:
b^e1 *= b^e2→b^(e1+e2)when this andthatshare the same Power-level conjugation flag.b^e *= B→b^(e+1)for a bare scalarBequal 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
thatis not combinable.
Public Static Functions
-
static inline void flatten(ExprPtr &expr)¶
Attempts to flatten a Power, mutating
exprin place. Folds whenexprholds a Power and any of:the exponent is 1 (then
b^1 = band conjugate if needed);the exponent is 0 (then
b^0 = 1for any base);the base is the
Constant1 (then1^k = 1for any rationalk);the base is a Constant and the exponent is a real integer;
the base is a Constant and the exponent has the form
m/2and the base is a non-negative real rationalp/qwith bothpandqperfect squares (e.g.4^{1/2} -> 2,(1/4)^{1/2} -> 1/2). On success,expris rebound to the folded expression; otherwise it is left unchanged.
Note
Only square-root exponents are folded (that is the only case needed in practice right now). Extending to general n-th roots only requires replacing the integer-square-root step with an integer n-th-root.
-
Power() = delete¶