14 if (!std::isfinite(
value)) {
17 "finite interval endpoint evaluated to NaN or infinity",
26 const int binary_exponent =
exponent - 53;
27 const std::size_t required_bits = binary_exponent < 0
28 ?
static_cast<std::size_t
>(-binary_exponent) + 1
29 :
static_cast<std::size_t
>(binary_exponent) + 54;
42 const std::shared_ptr<const SymbolicNode>&
node);
50 right.radical_coefficient != Rational(0) &&
69 const bool right_radical =
right.radical_coefficient != Rational(0);
70 if (left_radical && right_radical && left.
radicand !=
right.radicand) {
73 const Rational radicand = left_radical ? left.
radicand :
right.radicand;
76 const Rational coefficient =
84 for (
const auto& operand :
add.operands()) {
93 result = std::move(*combined);
100 for (
const auto& operand : multiply.operands()) {
109 result = std::move(*combined);
121 if (!radicand || *radicand <= Rational(0)) {
127 if (!base || *
exponent != Rational(-1)) {
130 const Rational norm = base->rational * base->rational -
131 base->radical_coefficient * base->radical_coefficient * base->radicand;
132 if (norm == Rational(0)) {
137 base->rational / norm,
138 (Rational(0) - base->radical_coefficient) / norm,
143 const std::shared_ptr<const SymbolicNode>&
node) {
151 if (
auto function = std::dynamic_pointer_cast<const FunctionNode>(
node)) {
153 function->arguments().size() != 1) {
157 if (!radicand || *radicand <= Rational(0)) {
163 if (
auto add = std::dynamic_pointer_cast<const AddNode>(
node)) {
166 if (
auto multiply = std::dynamic_pointer_cast<const MultiplyNode>(
node)) {
169 if (
auto power = std::dynamic_pointer_cast<const PowerNode>(
node)) {
177 const std::string&) {
178 if (std::holds_alternative<BigInt>(number.
value())) {
180 0, Rational(std::get<BigInt>(number.
value())),
181 Rational(0), Rational(0)});
184 0, std::get<Rational>(number.
value()), Rational(0), Rational(0)});
199 b > Rational(0) ? 1 : 0, 1,
context);
203 surd.
algebraic = std::move(algebraic.value());
216 auto*
real = std::get_if<LMCAS::detail::RealIsolation>(
221 "interval endpoint RootOf is not real",
230 if (
function.arguments().size() != 1) {
238 return *argument <= Rational(0);
241 *argument < Rational(0);
245 const std::shared_ptr<const SymbolicNode>&
node,
const std::string&
operation) {
246 if (
auto variable = std::dynamic_pointer_cast<const VariableNode>(
node);
250 "interval endpoint contains unbound symbol '" +
variable->name() +
"'",
253 if (
auto function = std::dynamic_pointer_cast<const FunctionNode>(
node)) {
257 "interval endpoint is outside the real function domain",
263 "exact ordering of a symbolic interval endpoint is not proven",
271 (
context).limits().max_ast_nodes,
"transform");
275 "finite interval endpoint must contain an expression",
283 "interval endpoint simplification produced a null expression",
288 if (
auto number = std::dynamic_pointer_cast<const NumberNode>(
node)) {
294 if (
auto root = std::dynamic_pointer_cast<const RootOfNode>(
node)) {
300}
catch (
const std::bad_alloc&) {
302}
catch (
const std::length_error& error) {
304}
catch (
const std::exception& error) {
311 const Endpoint& endpoint,
319 if (endpoint.is_neg_infinity && endpoint.is_pos_infinity) {
322 "an endpoint cannot be both negative and positive infinity",
325 if (endpoint.is_neg_infinity || endpoint.is_pos_infinity) {
326 if (endpoint.value) {
329 "infinite endpoints cannot also contain a finite value",
332 if (!endpoint.is_open) {
335 "infinite interval endpoints must be open",
340 Rational(0), Rational(0), Rational(0)});
函数节点,表示数学函数调用(三角函数、对数、特殊函数等)。
const std::variant< BigInt, Rational > & value() const noexcept
const std::shared_ptr< const SymbolicNode > & exponent() const noexcept
const std::shared_ptr< const SymbolicNode > & base() const noexcept
static Result failure(CasErrc code, std::string message, std::string operation={})
static Result success(T value)
const LMCAS::detail::ExactRootId & exact_id() const noexcept
std::optional< ComparableEndpoint > combine_surd_sum(const ComparableEndpoint &left, const ComparableEndpoint &right)
std::optional< ComparableEndpoint > parse_surd_product(const MultiplyNode &multiply)
std::optional< ComparableEndpoint > combine_surd_product(const ComparableEndpoint &left, const ComparableEndpoint &right)
Result< ComparableEndpoint > unsupported_endpoint(const std::shared_ptr< const SymbolicNode > &node, const std::string &operation)
Result< ComparableEndpoint > comparable_number(const NumberNode &number, ComputationContext &, const std::string &)
Result< ComparableEndpoint > comparable_surd(ComparableEndpoint surd, ComputationContext &context)
Result< ComparableEndpoint > comparable_root(const RootOfNode &root, ComputationContext &context, const std::string &operation)
std::optional< ComparableEndpoint > parse_surd_power(const PowerNode &power)
bool outside_real_function_domain(const FunctionNode &function)
std::optional< ComparableEndpoint > parse_quadratic_surd(const std::shared_ptr< const SymbolicNode > &node)
Result< ComparableEndpoint > comparable_finite_endpoint(const Endpoint &endpoint, ComputationContext &context, const std::string &operation)
std::optional< ComparableEndpoint > parse_surd_sum(const AddNode &add)
Result< ComparableEndpoint > comparable_endpoint(const Endpoint &endpoint, ComputationContext &context, const std::string &operation)
std::shared_ptr<::LMCAS::SymbolicExpr > make_expression_ptr(SymbolicNodePtr root)
const SymbolicNodePtr & node(const ::LMCAS::SymbolicExpr &expression) noexcept
Result< Rational > exact_double_rational(double value, ComputationContext &context, const std::string &operation)
Result< RootIsolation > isolate_exact_root(const ExactRootId &root, ComputationContext &context, const std::string &operation)
const std::string & variable
ComputationContext const std::string & operation
std::optional< Rational > exact_rational_value(const NumberNode &number)
SymbolicNodePtr normalize_node(const SymbolicNodePtr &node, RewriteBudget &budget, const FactsQuery &facts, Domain domain)
ExactRealAlgebraicResult make_exact_real_algebraic(Polynomial< Rational > polynomial, std::size_t root_index, std::size_t multiplicity, ComputationContext &context)
std::size_t std::size_t ComputationContext & context
ExprResult real(const ExprPtr &expression, ComputationContext &context)
ExprResult add(const ExprPtr &lhs, const ExprPtr &rhs, ComputationContext &context)
__attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) std const VectorField const std::string const std::shared_ptr< SymbolicExpr > & a
const std::string const ExprPtr & value
ExprResult function(const std::string &name, std::vector< ExprPtr > arguments)
ExprResult rational(const Rational &value)
Rational radical_coefficient
std::optional< LMCAS::detail::ExactRealAlgebraic > algebraic