13 return exponent == BigInt(1) ? base :
14 SymbolicExpr::power(base, SymbolicExpr::number(
exponent));
19std::shared_ptr<SymbolicExpr> Irrational::Basis::to_symbolic()
const {
20 std::shared_ptr<SymbolicExpr> result;
21 auto append = [&](std::shared_ptr<SymbolicExpr> factor) {
22 result = result ? SymbolicExpr::multiply(result, std::move(factor)) : std::move(factor);
26 if (radicand != BigInt(1)) append(SymbolicExpr::sqrt(SymbolicExpr::number(radicand)));
27 return result ? result : SymbolicExpr::number(1);
30std::shared_ptr<SymbolicExpr> Irrational::terms_to_symbolic(
const Terms& terms) {
31 std::shared_ptr<SymbolicExpr> result;
32 for (
const auto& term : terms) {
33 auto expression = term.first.is_constant() ? SymbolicExpr::number(term.second) :
34 term.first.to_symbolic();
35 if (!term.first.is_constant() && term.second !=
Rational(1)) {
36 expression = SymbolicExpr::multiply(SymbolicExpr::number(term.second), expression);
38 result = result ? SymbolicExpr::add(result, expression) : expression;
40 return result ? result : SymbolicExpr::number(0);
43std::shared_ptr<SymbolicExpr> Irrational::to_symbolic()
const {
44 const auto rational = as_rational_checked();
46 auto numerator = terms_to_symbolic(numerator_);
47 if (denominator_.size() == 1 && denominator_.begin()->first.is_constant() &&
48 denominator_.begin()->second ==
Rational(1))
return numerator;
49 return SymbolicExpr::divide(numerator, terms_to_symbolic(denominator_));
std::shared_ptr< SymbolicExpr > symbolic_named_power(const std::string &name, const BigInt &exponent)
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
std::shared_ptr< const Node > make_node(Args &&... args)
@ Rational
Rational numbers
__attribute__((visibility("default"))) Result< EqvProfile > eqv_profile_from_name(const std const std::string & name
ExprResult rational(const Rational &value)
符号表达式主类 SymbolicExpr 及其工厂方法,运算接口.