LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
interval_endpoint_order.cpp
浏览该文件的文档.
1
#include "
internal/interval_endpoint.hpp
"
2
3
namespace
LMCAS::detail
{
4
namespace
{
5
6
int
rational_sign
(
const
Rational&
value
) {
7
if
(
value
== Rational(0)) {
8
return
0;
9
}
10
return
value
.get_numerator().is_negative() ? -1 : 1;
11
}
12
13
int
compare_rationals
(
const
Rational& left,
const
Rational&
right
) {
14
if
(left <
right
) {
15
return
-1;
16
}
17
if
(left >
right
) {
18
return
1;
19
}
20
return
0;
21
}
22
23
int
compare_algebraic_to_rational
(
24
const
ExactRealAlgebraic
& algebraic,
const
Rational&
rational
) {
25
if
(algebraic.
upper
<
rational
) {
26
return
-1;
27
}
28
if
(
rational
< algebraic.
lower
) {
29
return
1;
30
}
31
const
Rational
value
= algebraic.
polynomial
.
eval
(
rational
);
32
if
(
value
== Rational(0)) {
33
return
0;
34
}
35
const
Rational lower_value =
36
algebraic.
polynomial
.
eval
(algebraic.
lower
);
37
const
bool
root_before_rational =
38
rational_sign
(lower_value) !=
rational_sign
(
value
);
39
return
root_before_rational ? -1 : 1;
40
}
41
42
ExactRealAlgebraicResult
to_algebraic
(
43
const
ComparableEndpoint
& endpoint,
ComputationContext
&
context
) {
44
if
(endpoint.
algebraic
) {
45
return
LMCAS::detail::ExactRealAlgebraicResult::success
(
46
*endpoint.
algebraic
);
47
}
48
if
(endpoint.
radical_coefficient
== Rational(0)) {
49
return
LMCAS::detail::make_exact_real_algebraic
(
50
Polynomial<Rational>
({
51
Rational(0) - endpoint.
rational
,
52
Rational(1)
53
}),
54
0, 1,
context
);
55
}
56
const
Rational
a
= endpoint.
rational
;
57
const
Rational
b
= endpoint.
radical_coefficient
;
58
const
Rational d = endpoint.
radicand
;
59
auto
value
=
LMCAS::detail::make_exact_real_algebraic
(
60
Polynomial<Rational>
({
61
a
*
a
-
b
*
b
* d,
62
Rational(-2) *
a
,
63
Rational(1)
64
}),
65
b
> Rational(0) ? 1 : 0, 1,
context
);
66
return
value
;
67
}
68
69
}
70
71
Result<int>
compare_comparable
(
const
ComparableEndpoint
& left,
72
const
ComparableEndpoint
&
right
,
73
ComputationContext
&
context
) {
74
if
(left.
infinity
<
right
.infinity) {
75
return
Result<int>::success
(-1);
76
}
77
if
(left.
infinity
>
right
.infinity) {
78
return
Result<int>::success
(1);
79
}
80
if
(left.
infinity
!= 0) {
81
return
Result<int>::success
(0);
82
}
83
84
const
bool
left_radical =
85
left.
radical_coefficient
!= Rational(0) || left.
algebraic
.has_value();
86
const
bool
right_radical =
87
right
.radical_coefficient != Rational(0) ||
right
.algebraic.has_value();
88
if
(!left_radical && !right_radical) {
89
return
Result<int>::success
(compare_rationals(left.
rational
,
right
.rational));
90
}
91
if
(left.
algebraic
&& !right_radical) {
92
return
Result<int>::success
(
93
compare_algebraic_to_rational(*left.
algebraic
,
right
.rational));
94
}
95
if
(
right
.algebraic && !left_radical) {
96
return
Result<int>::success
(
97
-compare_algebraic_to_rational(*
right
.algebraic, left.
rational
));
98
}
99
auto
left_algebraic = to_algebraic(left,
context
);
100
if
(!left_algebraic) {
101
return
Result<int>::failure
(left_algebraic.error());
102
}
103
auto
right_algebraic = to_algebraic(
right
,
context
);
104
if
(!right_algebraic) {
105
return
Result<int>::failure
(right_algebraic.error());
106
}
107
return
LMCAS::detail::compare_exact_real_algebraic
(
108
left_algebraic.value(), right_algebraic.value(),
context
);
109
}
110
111
}
LMCAS::ComputationContext
定义
computation_context.hpp:99
LMCAS::Polynomial
一元多项式模板类
定义
polynomial.hpp:52
LMCAS::Polynomial::eval
CoeffType eval(const CoeffType &val) const
对多项式求值(Horner 法)
定义
polynomial.hpp:294
LMCAS::Result
定义
result.hpp:39
LMCAS::Result::failure
static Result failure(CasErrc code, std::string message, std::string operation={})
定义
result.hpp:52
LMCAS::Result< ExactRealAlgebraic >::success
static Result success(ExactRealAlgebraic value)
定义
result.hpp:48
interval_endpoint.hpp
LMCAS::detail::anonymous_namespace{interval_endpoint_order.cpp}::compare_algebraic_to_rational
int compare_algebraic_to_rational(const ExactRealAlgebraic &algebraic, const Rational &rational)
定义
interval_endpoint_order.cpp:23
LMCAS::detail::anonymous_namespace{interval_endpoint_order.cpp}::rational_sign
int rational_sign(const Rational &value)
定义
interval_endpoint_order.cpp:6
LMCAS::detail::anonymous_namespace{interval_endpoint_order.cpp}::compare_rationals
int compare_rationals(const Rational &left, const Rational &right)
定义
interval_endpoint_order.cpp:13
LMCAS::detail::anonymous_namespace{interval_endpoint_order.cpp}::to_algebraic
ExactRealAlgebraicResult to_algebraic(const ComparableEndpoint &endpoint, ComputationContext &context)
定义
interval_endpoint_order.cpp:42
LMCAS::detail
多元 Hensel 提升(单变量步)
定义
assumption_context.hpp:31
LMCAS::detail::compare_exact_real_algebraic
Result< int > compare_exact_real_algebraic(ExactRealAlgebraic lhs, ExactRealAlgebraic rhs, ComputationContext &context)
定义
exact_algebraic.cpp:206
LMCAS::detail::ExactRealAlgebraicResult
Result< ExactRealAlgebraic > ExactRealAlgebraicResult
定义
exact_algebraic.hpp:21
LMCAS::detail::make_exact_real_algebraic
ExactRealAlgebraicResult make_exact_real_algebraic(Polynomial< Rational > polynomial, std::size_t root_index, std::size_t multiplicity, ComputationContext &context)
定义
exact_algebraic.cpp:65
LMCAS::detail::context
std::size_t std::size_t ComputationContext & context
定义
exact_algebraic.hpp:27
LMCAS::detail::compare_comparable
Result< int > compare_comparable(const ComparableEndpoint &left, const ComparableEndpoint &right, ComputationContext &context)
定义
interval_endpoint_order.cpp:71
LMCAS::b
const MultiPoly & b
定义
multivariate_factor.hpp:92
LMCAS::a
__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
定义
vector_calculus_curves.hpp:50
LMCAS::right
const ExprPtr & right
定义
residual_verification.hpp:50
LMCAS::value
const std::string const ExprPtr & value
定义
expr.hpp:293
LMCAS::rational
ExprResult rational(const Rational &value)
定义
expr_values.cpp:82
LMCAS::detail::ComparableEndpoint
定义
interval_endpoint.hpp:10
LMCAS::detail::ComparableEndpoint::rational
Rational rational
定义
interval_endpoint.hpp:12
LMCAS::detail::ComparableEndpoint::infinity
int infinity
定义
interval_endpoint.hpp:11
LMCAS::detail::ComparableEndpoint::radical_coefficient
Rational radical_coefficient
定义
interval_endpoint.hpp:13
LMCAS::detail::ComparableEndpoint::algebraic
std::optional< LMCAS::detail::ExactRealAlgebraic > algebraic
定义
interval_endpoint.hpp:15
LMCAS::detail::ComparableEndpoint::radicand
Rational radicand
定义
interval_endpoint.hpp:14
LMCAS::detail::ExactRealAlgebraic
定义
exact_algebraic.hpp:11
LMCAS::detail::ExactRealAlgebraic::polynomial
Polynomial< Rational > polynomial
定义
exact_algebraic.hpp:12
LMCAS::detail::ExactRealAlgebraic::lower
Rational lower
定义
exact_algebraic.hpp:13
LMCAS::detail::ExactRealAlgebraic::upper
Rational upper
定义
exact_algebraic.hpp:14
src
interval_endpoint_order.cpp
生成于
, 为 LMCAS使用
1.18.0