LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
exact_constant_bounds.hpp
浏览该文件的文档.
1
#pragma once
2
3
#include "
computation_context.hpp
"
4
#include "
rational.hpp
"
5
#include <algorithm>
6
#include <limits>
7
#include <utility>
8
9
namespace
LMCAS::detail
{
10
11
using
ExactConstantInterval
= std::pair<Rational, Rational>;
12
Result<ExactConstantInterval>
exact_atan_bounds
(
13
const
Rational&
value
, std::size_t precision_bits,
ComputationContext
&
context
);
14
Result<ExactConstantInterval>
exact_pi_bounds
(
15
std::size_t precision_bits,
ComputationContext
&
context
);
16
Result<ExactConstantInterval>
exact_e_bounds
(
17
std::size_t precision_bits,
ComputationContext
&
context
);
18
19
/**
20
* @brief 常数及根式包围区间共用的内部算术策略。
21
* 保守界覆盖未约分 Rational 的交叉乘积及结果;受检入口统一捕获 CasError,仅返回完整结果。
22
*/
23
class
ExactBoundArithmetic
{
24
public
:
25
ExactBoundArithmetic
(
ComputationContext
&
context
,
const
char
*
operation
)
26
:
context_
(
context
),
operation_
(
operation
) {}
27
28
void
require
(
Result<void>
result)
const
{
29
if
(!result)
throw
result.
error
();
30
}
31
void
step
()
const
{
require
(
context_
.
consume_steps
(1,
operation_
)); }
32
void
bits
(std::size_t count)
const
{
33
require
(
context_
.
require_integer_bits
(count,
operation_
));
34
}
35
std::size_t
growth
(std::size_t
a
, std::size_t
b
)
const
{
36
if
(
b
> std::numeric_limits<std::size_t>::max() -
a
)
37
throw
CasError
{
CasErrc::ResourceLimit
,
"integer size overflow"
,
operation_
};
38
const
auto
size =
a
+
b
;
39
bits
(size);
40
return
size;
41
}
42
void
operands
(
const
Rational&
a
,
const
Rational&
b
,
bool
addition =
false
)
const
{
43
step
();
44
const
auto
a_bits = std::max(
a
.get_numerator().bit_length(),
45
a
.get_denominator().bit_length());
46
const
auto
b_bits = std::max(
b
.get_numerator().bit_length(),
47
b
.get_denominator().bit_length());
48
const
auto
size =
growth
(a_bits, b_bits);
49
if
(addition)
growth
(size, 1);
50
}
51
Rational
add
(
const
Rational&
a
,
const
Rational&
b
)
const
{
52
operands
(
a
,
b
,
true
);
return
a
+
b
;
53
}
54
Rational
sub
(
const
Rational&
a
,
const
Rational&
b
)
const
{
55
operands
(
a
,
b
,
true
);
return
a
-
b
;
56
}
57
Rational
mul
(
const
Rational&
a
,
const
Rational&
b
)
const
{
58
operands
(
a
,
b
);
return
a
*
b
;
59
}
60
Rational
div
(
const
Rational&
a
,
const
Rational&
b
)
const
{
61
operands
(
a
,
b
);
62
if
(
b
.is_zero())
63
throw
CasError
{
CasErrc::DomainError
,
"zero enclosure divisor"
,
operation_
};
64
return
a
/
b
;
65
}
66
bool
less
(
const
Rational&
a
,
const
Rational&
b
)
const
{
67
operands
(
a
,
b
);
return
a
<
b
;
68
}
69
BigInt
dyadic_scale
(std::size_t precision)
const
{
70
step
();
71
growth
(precision, 1);
72
if
(precision > std::numeric_limits<mp_size_t>::max())
73
throw
CasError
{
CasErrc::ResourceLimit
,
"shift size overflow"
,
operation_
};
74
return
BigInt(1) <<
static_cast<
mp_size_t
>
(precision);
75
}
76
private
:
77
ComputationContext
&
context_
;
78
const
char
*
operation_
;
79
};
80
81
}
LMCAS::ComputationContext
定义
computation_context.hpp:99
LMCAS::ComputationContext::consume_steps
Result< void > consume_steps(std::size_t amount=1, const std::string &operation={})
定义
computation_context.hpp:112
LMCAS::ComputationContext::require_integer_bits
Result< void > require_integer_bits(std::size_t amount, const std::string &operation={}) const
定义
computation_context.hpp:151
LMCAS::Result
定义
result.hpp:39
LMCAS::Result::error
CasError & error()
定义
result.hpp:77
LMCAS::detail::ExactBoundArithmetic::mul
Rational mul(const Rational &a, const Rational &b) const
定义
exact_constant_bounds.hpp:57
LMCAS::detail::ExactBoundArithmetic::step
void step() const
定义
exact_constant_bounds.hpp:31
LMCAS::detail::ExactBoundArithmetic::growth
std::size_t growth(std::size_t a, std::size_t b) const
定义
exact_constant_bounds.hpp:35
LMCAS::detail::ExactBoundArithmetic::ExactBoundArithmetic
ExactBoundArithmetic(ComputationContext &context, const char *operation)
定义
exact_constant_bounds.hpp:25
LMCAS::detail::ExactBoundArithmetic::add
Rational add(const Rational &a, const Rational &b) const
定义
exact_constant_bounds.hpp:51
LMCAS::detail::ExactBoundArithmetic::div
Rational div(const Rational &a, const Rational &b) const
定义
exact_constant_bounds.hpp:60
LMCAS::detail::ExactBoundArithmetic::less
bool less(const Rational &a, const Rational &b) const
定义
exact_constant_bounds.hpp:66
LMCAS::detail::ExactBoundArithmetic::dyadic_scale
BigInt dyadic_scale(std::size_t precision) const
定义
exact_constant_bounds.hpp:69
LMCAS::detail::ExactBoundArithmetic::context_
ComputationContext & context_
定义
exact_constant_bounds.hpp:77
LMCAS::detail::ExactBoundArithmetic::operands
void operands(const Rational &a, const Rational &b, bool addition=false) const
定义
exact_constant_bounds.hpp:42
LMCAS::detail::ExactBoundArithmetic::require
void require(Result< void > result) const
定义
exact_constant_bounds.hpp:28
LMCAS::detail::ExactBoundArithmetic::bits
void bits(std::size_t count) const
定义
exact_constant_bounds.hpp:32
LMCAS::detail::ExactBoundArithmetic::sub
Rational sub(const Rational &a, const Rational &b) const
定义
exact_constant_bounds.hpp:54
LMCAS::detail::ExactBoundArithmetic::operation_
const char * operation_
定义
exact_constant_bounds.hpp:78
computation_context.hpp
LMCAS::detail
多元 Hensel 提升(单变量步)
定义
assumption_context.hpp:31
LMCAS::detail::exact_e_bounds
Result< ExactConstantInterval > exact_e_bounds(std::size_t precision_bits, ComputationContext &context)
定义
exact_constant_bounds.cpp:114
LMCAS::detail::ExactConstantInterval
std::pair< Rational, Rational > ExactConstantInterval
定义
exact_constant_bounds.hpp:11
LMCAS::detail::exact_atan_bounds
Result< ExactConstantInterval > exact_atan_bounds(const Rational &value, std::size_t precision_bits, ComputationContext &context)
定义
exact_constant_bounds.cpp:100
LMCAS::detail::operation
ComputationContext const std::string & operation
定义
exact_algebraic.hpp:32
LMCAS::detail::exact_pi_bounds
Result< ExactConstantInterval > exact_pi_bounds(std::size_t precision_bits, ComputationContext &context)
定义
exact_constant_bounds.cpp:107
LMCAS::detail::context
std::size_t std::size_t ComputationContext & context
定义
exact_algebraic.hpp:27
LMCAS::CasErrc::ResourceLimit
@ ResourceLimit
定义
result.hpp:25
LMCAS::CasErrc::DomainError
@ DomainError
定义
result.hpp:16
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::value
const std::string const ExprPtr & value
定义
expr.hpp:293
LMCAS::CasError
定义
result.hpp:31
rational.hpp
精确有理数 Rational,基于 BigInt 分子/分母表示,自动约分。
src
internal
exact_constant_bounds.hpp
生成于
, 为 LMCAS使用
1.18.0