LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
series_engine.hpp
浏览该文件的文档.
1/**
2 * @file series_engine.hpp
3 * @brief 级数引擎模块:收敛性判定,幂级数运算,傅里叶级数,洛朗级数,渐近展开,符号求和与乘积.
4 */
5#pragma once
6
8#include "result.hpp"
9#include "symbolic.hpp"
10#include <vector>
11#include <string>
12#include <memory>
13
14namespace LMCAS {
15
17
18
19/**
20 * @brief 收敛性结果枚举.
21 */
23 Convergent, ///< 收敛
24 Divergent, ///< 发散
25 Inconclusive ///< 无法判定
26};
27
28/**
29 * @brief 收敛性判定信息.
30 */
32 ConvergenceResult result; ///< 判定结果
33 std::string test_used; ///< 使用的判定方法("ratio", "root", "comparison")
34};
35
37
38/**
39 * @brief 从无限级数通项计算幂级数收敛半径.
40 *
41 * 当前对常数通项,b^n 和 n^p 给出精确结果;无法证明尾项行为时返回
42 * ::CasErrc::Inconclusive,不会从有限样本外推极限.
43 *
44 * @param[in] general_coefficient 系数通项 a_n
45 * @param[in] index_var 系数指标变量名
46 * @return 已证明的收敛半径表达式
47 */
49 const std::shared_ptr<SymbolicExpr>& general_coefficient,
50 const std::string& index_var,
52
54 const std::shared_ptr<SymbolicExpr>& general_coefficient,
55 const std::string& index_var);
56
57/**
58 * @brief 返回有限系数多项式的收敛半径.
59 *
60 * coefficients 完整表示有限多项式,未列出的高阶系数均为零,因此非空
61 * 有效输入的收敛半径恒为 infinity.若要表示无限级数,应使用通项重载;
62 * 有限前缀不足以证明无限尾项的收敛半径.
63 */
65 const std::vector<std::shared_ptr<SymbolicExpr>>& coefficients,
66 const std::string& var,
68
70 const std::vector<std::shared_ptr<SymbolicExpr>>& coefficients,
71 const std::string& var);
72
73
74/**
75 * @brief 判定无穷级数的收敛性.
76 *
77 * 依次尝试比值判别法,根值判别法和比较判别法.
78 *
79 * @param[in] general_term 通项表达式 a_n
80 * @param[in] index_var 求和指标变量名
81 * @return 收敛性判定信息
82 */
84 const std::shared_ptr<SymbolicExpr>& general_term,
85 const std::string& index_var,
87
89 const std::shared_ptr<SymbolicExpr>& general_term,
90 const std::string& index_var);
91
92
93
94/**
95 * @brief 幂级数加法:逐项相加.
96 *
97 * @param[in] a 第一个幂级数系数列表
98 * @param[in] b 第二个幂级数系数列表
99 * @return 和级数的系数列表
100 */
101LMCAS_API std::vector<std::shared_ptr<SymbolicExpr>> power_series_add(
102 const std::vector<std::shared_ptr<SymbolicExpr>>& a,
103 const std::vector<std::shared_ptr<SymbolicExpr>>& b);
104
105/**
106 * @brief 幂级数乘法:柯西乘积(卷积).
107 *
108 * @param[in] a 第一个幂级数系数列表
109 * @param[in] b 第二个幂级数系数列表
110 * @param[in] order 截断阶数
111 * @return 乘积级数的系数列表(截断到 order 项)
112 */
114 const std::vector<std::shared_ptr<SymbolicExpr>>& a,
115 const std::vector<std::shared_ptr<SymbolicExpr>>& b, int order,
117
119 const std::vector<std::shared_ptr<SymbolicExpr>>& a,
120 const std::vector<std::shared_ptr<SymbolicExpr>>& b, int order);
121
122
123/**
124 * @brief 幂级数复合:计算 f(g(x)) 的系数,要求 g(0) = 0.
125 *
126 * @param[in] f 外层幂级数系数列表
127 * @param[in] g 内层幂级数系数列表(g[0] 必须为 0)
128 * @param[in] order 截断阶数
129 * @return 复合级数的系数列表
130 */
132 const std::vector<std::shared_ptr<SymbolicExpr>>& f,
133 const std::vector<std::shared_ptr<SymbolicExpr>>& g, int order,
135
137 const std::vector<std::shared_ptr<SymbolicExpr>>& f,
138 const std::vector<std::shared_ptr<SymbolicExpr>>& g, int order);
139
140
141
142/**
143 * @brief Computes a bounded truncated Fourier expansion.
144 *
145 * All coefficient integrations share @p context. Resource exhaustion,
146 * cancellation, invalid inputs, and nested integration failures are returned
147 * without being collapsed to a null expression.
148 */
150 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
151 const std::shared_ptr<SymbolicExpr>& period, int n_terms,
153
155 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
156 const std::shared_ptr<SymbolicExpr>& period, int n_terms);
157
158
159/**
160 * @brief 奇点类型枚举.
161 */
162enum class SingularityType {
163 Removable, ///< 可去奇点
164 Pole, ///< 极点
165 Essential ///< 本性奇点
166};
167
168/**
169 * @brief 洛朗级数展开结果.
170 */
172 std::shared_ptr<SymbolicExpr> series; ///< 洛朗级数表达式
173 SingularityType singularity; ///< 奇点类型
174 int pole_order; ///< 极点阶数(非极点时为 0)
175 std::shared_ptr<SymbolicExpr> residue; ///< 留数((z-z_0)-¹ 的系数)
176};
177
179
180/**
181 * @brief 计算函数在指定点的洛朗级数展开.
182 *
183 * 展开包含从 (z-z_0)^(-order_neg) 到 (z-z_0)^(order_pos) 的项.
184 * 通过计算 (z-z_0)^k * f(z) 在 z_0 处的极限和导数来确定负幂次系数.
185 * 根据洛朗系数判定奇点类型:
186 * - 所有负幂次系数为零 -> 可去奇点
187 * - 有限个非零负幂次系数 -> m 阶极点
188 * - 无穷多非零负幂次系数 -> 本性奇点
189 *
190 * @param[in] f 待展开的函数表达式
191 * @param[in] var 变量名
192 * @param[in] center 展开中心 z_0
193 * @param[in] order_neg 负幂次最大阶数
194 * @param[in] order_pos 正幂次最大阶数
195 * @return 洛朗级数表达式
196 */
198 const std::shared_ptr<SymbolicExpr>& f,
199 const std::string& var,
200 const std::shared_ptr<SymbolicExpr>& center,
201 int order_neg,
202 int order_pos,
204
206 const std::shared_ptr<SymbolicExpr>& f,
207 const std::string& var,
208 const std::shared_ptr<SymbolicExpr>& center,
209 int order_neg,
210 int order_pos);
211
212
213/**
214 * @brief 计算函数在指定点的洛朗级数展开(含详细信息).
215 *
216 * @param[in] f 待展开的函数表达式
217 * @param[in] var 变量名
218 * @param[in] center 展开中心 z_0
219 * @param[in] order_neg 负幂次最大阶数
220 * @param[in] order_pos 正幂次最大阶数
221 * @return 洛朗级数展开结果(含奇点分类和留数)
222 */
224 const std::shared_ptr<SymbolicExpr>& f,
225 const std::string& var,
226 const std::shared_ptr<SymbolicExpr>& center,
227 int order_neg,
228 int order_pos,
230
232 const std::shared_ptr<SymbolicExpr>& f,
233 const std::string& var,
234 const std::shared_ptr<SymbolicExpr>& center,
235 int order_neg,
236 int order_pos);
237
238
239
240/**
241 * @brief 计算函数在 x->infinity 时的渐近展开.
242 *
243 * 将函数展开为递减幂次的和:sum cₖ * x^alphaₖ,其中 alpha_1 > alpha_2 > ... > alpha_n.
244 * 对有理函数使用多项式长除法;对含 exp,ln,幂函数的复合表达式使用已知渐近恒等式.
245 *
246 * @param[in] f 待展开的函数表达式
247 * @param[in] var 变量名
248 * @param[in] order 展开项数
249 * @return 渐近展开表达式
250 */
251LMCAS_API std::shared_ptr<SymbolicExpr> asymptotic_expand(
252 const std::shared_ptr<SymbolicExpr>& f, const std::string& var, int order);
253
254
255/**
256 * @brief 计算符号求和 sum_{k=lower}^{upper} body(k) 的闭合形式.
257 *
258 * 对多项式通项使用 Faulhaber 公式;对有理函数通项尝试部分分式分解和望远镜求和;
259 * 对几何/指数通项使用等比级数公式;其余通项映射为未求值 SummationNode.
260 *
261 * @param[in] body 通项表达式
262 * @param[in] index 求和指标变量名
263 * @param[in] lower 下界
264 * @param[in] upper 上界
265 * @return 求和结果表达式
266 */
267LMCAS_API std::shared_ptr<SymbolicExpr> symbolic_sum(
268 const std::shared_ptr<SymbolicExpr>& body, const std::string& index,
269 const std::shared_ptr<SymbolicExpr>& lower, const std::shared_ptr<SymbolicExpr>& upper);
270
271
272/**
273 * @brief 计算符号乘积 prod_{k=lower}^{upper} body(k) 的闭合形式.
274 *
275 * 对望远镜乘积和阶乘/Pochhammer 符号使用已知公式;
276 * 其余通项映射为未求值 ProductNode.
277 *
278 * @param[in] body 通项表达式
279 * @param[in] index 乘积指标变量名
280 * @param[in] lower 下界
281 * @param[in] upper 上界
282 * @return 乘积结果表达式
283 */
284LMCAS_API std::shared_ptr<SymbolicExpr> symbolic_product(
285 const std::shared_ptr<SymbolicExpr>& body, const std::string& index,
286 const std::shared_ptr<SymbolicExpr>& lower, const std::shared_ptr<SymbolicExpr>& upper);
287
288
289/**
290 * @brief 计算数列的上极限.
291 */
293 const std::shared_ptr<SymbolicExpr>& a_n, const std::string& n,
295
297 const std::shared_ptr<SymbolicExpr>& a_n, const std::string& n);
298
299/**
300 * @brief 计算数列的下极限.
301 */
303 const std::shared_ptr<SymbolicExpr>& a_n, const std::string& n,
305
307 const std::shared_ptr<SymbolicExpr>& a_n, const std::string& n);
308
309} // namespace LMCAS
#define LMCAS_API
std::shared_ptr< SymbolicExpr > symbolic_product(const std::shared_ptr< SymbolicExpr > &body, const std::string &index, const std::shared_ptr< SymbolicExpr > &lower, const std::shared_ptr< SymbolicExpr > &upper)
ExpressionResult fourier_series_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &period, int n_terms, ComputationContext &context)
Result< ConvergenceInfo > ConvergenceInfoResult
ConvergenceResult
收敛性结果枚举.
__attribute__((visibility("default"))) ExprResult function(const std __attribute__((visibility("default"))) ExprResult finite_set(std ExprPtr upper
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
PowerSeriesResult power_series_multiply_checked(const std::vector< std::shared_ptr< SymbolicExpr > > &a, const std::vector< std::shared_ptr< SymbolicExpr > > &b, int order, ComputationContext &context)
ConvergenceResult result
判定结果
SingularityType singularity
奇点类型
std::shared_ptr< SymbolicExpr > symbolic_sum(const std::shared_ptr< SymbolicExpr > &body, const std::string &index, const std::shared_ptr< SymbolicExpr > &lower, const std::shared_ptr< SymbolicExpr > &upper)
const ExprPtr & lower
const std::vector< FGLMPoly > const MonomialOrder & order
ExpressionResult laurent_series_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &center, int order_neg, int order_pos, ComputationContext &context)
@ Essential
本性间断点:至少一侧极限不存在或为无穷
@ Removable
可去间断点:左极限 = 右极限 != 函数值(或函数无定义)
Result< std::vector< std::shared_ptr< SymbolicExpr > > > PowerSeriesResult
ExpressionResult lim_inf_checked(const std::shared_ptr< SymbolicExpr > &a_n, const std::string &n, ComputationContext &context)
int pole_order
极点阶数(非极点时为 0)
const MultiPoly & b
Result< std::shared_ptr< SymbolicExpr > > ExpressionResult
Result of an operation that produces a symbolic expression.
ConvergenceInfoResult convergence_test_checked(const std::shared_ptr< SymbolicExpr > &general_term, const std::string &index_var, ComputationContext &context)
std::string test_used
使用的判定方法("ratio", "root", "comparison")
__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
LaurentSeriesResult laurent_series_full_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &center, int order_neg, int order_pos, ComputationContext &context)
@ Divergent
Diverges to infinity or oscillates
Result< LaurentResult > LaurentSeriesResult
std::shared_ptr< SymbolicExpr > residue
留数((z-z_0)-¹ 的系数)
PowerSeriesResult power_series_compose_checked(const std::vector< std::shared_ptr< SymbolicExpr > > &f, const std::vector< std::shared_ptr< SymbolicExpr > > &g, int order, ComputationContext &context)
std::shared_ptr< SymbolicExpr > asymptotic_expand(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, int order)
std::shared_ptr< SymbolicExpr > series
洛朗级数表达式
std::vector< std::shared_ptr< SymbolicExpr > > power_series_add(const std::vector< std::shared_ptr< SymbolicExpr > > &a, const std::vector< std::shared_ptr< SymbolicExpr > > &b)
ExpressionResult lim_sup_checked(const std::shared_ptr< SymbolicExpr > &a_n, const std::string &n, ComputationContext &context)
ExpressionResult convergence_radius_checked(const std::shared_ptr< SymbolicExpr > &general_coefficient, const std::string &index_var, ComputationContext &context)
SingularityType
从无限级数通项计算幂级数收敛半径.
洛朗级数展开结果.
收敛性判定信息.
符号表达式主类 SymbolicExpr 及其工厂方法,运算接口.