LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
calculus_utils.hpp
浏览该文件的文档.
1/**
2 * @file calculus_utils.hpp
3 * @brief 微积分工具函数:连续性判定,渐近线分析,对数微分,微分,全微分,反函数导数,反函数求解等.
4 */
5#pragma once
6
8#include "result.hpp"
9#include "symbolic.hpp"
10#include <vector>
11#include <string>
12#include <utility>
13#include <memory>
14
15namespace LMCAS {
16
17
18/**
19 * @brief 连续性类型枚举.
20 */
21enum class ContinuityType {
22 Continuous, ///< 连续:左极限 = 右极限 = 函数值
23 Removable, ///< 可去间断点:左极限 = 右极限 != 函数值(或函数无定义)
24 Jump, ///< 跳跃间断点:左极限 != 右极限,但两侧极限均存在
25 Essential ///< 本性间断点:至少一侧极限不存在或为无穷
26};
27
29
30/**
31 * @brief 根据左右极限与函数值,在给定上下文假设下证明实数域中的连续性分类。
32 * 跳跃与可去间断的比较需证明逐点不等,相等性需保证各值有定义;形式非恒等不足以证明二者。
33 * 参数值或有定义性未确定时返回 Inconclusive;资源、取消和底层证明错误原样传播,不作为分类。
34 */
36 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
37 const std::shared_ptr<SymbolicExpr>& point, ComputationContext& context);
38
40 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
41 const std::shared_ptr<SymbolicExpr>& point);
42
43
44/**
45 * @brief 渐近线分析结果.
46 */
48 std::vector<std::shared_ptr<SymbolicExpr>> vertical; ///< 垂直渐近线 x = a
49 std::vector<std::shared_ptr<SymbolicExpr>> horizontal; ///< 水平渐近线 y = L
50 std::vector<std::pair<std::shared_ptr<SymbolicExpr>,
51 std::shared_ptr<SymbolicExpr>>> oblique; ///< 斜渐近线 (斜率, 截距)
52};
53
56
57/**
58 * @brief 计算函数的渐近线.
59 *
60 * 垂直渐近线:分母为零且极限为 +/-infinity 的点.
61 * 水平渐近线:x->+/-infinity 时的极限值.
62 * 斜渐近线:当无水平渐近线时,计算 slope = lim(f/x) 和 intercept = lim(f - slope*x).
63 *
64 * @param[in] f 待分析的函数表达式
65 * @param[in] var 自变量名
66 * @return 渐近线分析结果
67 */
69 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
71
72/**
73 * @brief 使用默认计算上下文计算函数的渐近线,并显式报告无效输入.
74 */
76 const std::shared_ptr<SymbolicExpr>& f, const std::string& var);
77
78
79
80/**
81 * @brief 对数微分法:计算 f 关于 var 的导数.
82 *
83 * 利用公式 d/dx[f] = f * d/dx[ln(f)],对 ln(f) 先应用对数化简规则
84 * (乘积变求和,幂次提前)再求导,适用于 x^x 或多项乘积等复杂表达式.
85 *
86 * @param[in] f 待求导的表达式
87 * @param[in] var 求导变量名
88 * @return 对数微分结果表达式
89 */
90LMCAS_API std::shared_ptr<SymbolicExpr> log_differentiate(
91 const std::shared_ptr<SymbolicExpr>& f, const std::string& var);
92
93/**
94 * @brief 计算单变量微分 dy = f'(x)dx 中的系数 f'(x).
95 *
96 * 返回 f 关于 var 的导数,即微分 df 中 dx 的系数.
97 *
98 * @param[in] f 函数表达式
99 * @param[in] var 微分变量名
100 * @return f'(var) 表达式
101 */
102LMCAS_API std::shared_ptr<SymbolicExpr> differential(
103 const std::shared_ptr<SymbolicExpr>& f, const std::string& var);
104
105/**
106 * @brief 计算全微分 df = sum(partialf/partialxᵢ)*dxᵢ.
107 *
108 * 对多元函数 f 关于每个变量求偏导,返回 (偏导数, 变量名) 对的列表,
109 * 表示全微分中各项.
110 *
111 * @param[in] f 多元函数表达式
112 * @param[in] vars 变量名列表
113 * @return (partialf/partialxᵢ, "xᵢ") 对的向量
114 */
115LMCAS_API std::vector<std::pair<std::shared_ptr<SymbolicExpr>, std::string>> total_differential(
116 const std::shared_ptr<SymbolicExpr>& f, const std::vector<std::string>& vars);
117
118/**
119 * @brief 计算反函数导数 (f-¹)'(point) = 1 / f'(f-¹(point)).
120 *
121 * Checked API 只在反函数候选唯一且 f'(x_0) 可构造,非零时成功.
122 */
124 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
125 const std::shared_ptr<SymbolicExpr>& point,
127
128/**
129 * @brief 使用默认计算上下文计算反函数导数,并显式报告失败语义.
130 */
132 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
133 const std::shared_ptr<SymbolicExpr>& point);
134
135/**
136 * @brief 计算反函数导数 (f-¹)'(point) = 1 / f'(f-¹(point)).
137 *
138 * The convenience overload 先求解 f(x) = point 得到第一个 x_0,再计算
139 * 1/f'(x_0).若 f'(x_0) = 0 则返回 nullptr.
140 *
141 * @param[in] f 函数表达式
142 * @param[in] var 变量名
143 * @param[in] point 求导点(y 值)
144 * @return 反函数导数表达式;nullptr 表示输入位于当前支持域之外
145 */
146
147/**
148 * @brief 求解反函数 f-¹(y),即求解方程 f(x) = y 关于 x 的所有解.
149 *
150 * Checked API 使用 solution-set dispatcher;只在有限精确解或可证明空集
151 * 时成功,超出支持域返回 `CasErrc::Inconclusive`.
152 */
154 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
155 const std::shared_ptr<SymbolicExpr>& y, ComputationContext& context);
156
157/**
158 * @brief 使用默认计算上下文求解反函数,并显式报告失败语义.
159 */
161 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
162 const std::shared_ptr<SymbolicExpr>& y);
163
164/**
165 * @brief 求解反函数 f-¹(y),即求解方程 f(x) = y 关于 x 的所有解.
166 *
167 * The convenience overload 利用现有求解器将 f(var) - y = 0 求解,返回所有分支.
168 *
169 * @param[in] f 函数表达式
170 * @param[in] var 变量名
171 * @param[in] y 目标值表达式
172 * @return 所有解的列表
173 */
174
175
176/**
177 * @brief 计算显式曲线 y = f(x) 的曲率 κ = |f''| / (1 + f'^2)^(3/2)
178 * @param[in] f 曲线函数表达式 f(x)
179 * @param[in] var 自变量名称
180 * @return 曲率的符号表达式
181 */
183 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
185
186/**
187 * @brief 使用默认计算上下文计算显式曲线曲率,并显式报告无效输入.
188 */
190 const std::shared_ptr<SymbolicExpr>& f, const std::string& var);
191
192
193/**
194 * @brief 计算参数曲线 (x(t), y(t)) 的曲率 κ = |x'y'' - y'x''| / (x'^2 + y'^2)^(3/2)
195 * @param[in] x_t x 分量关于参数 t 的表达式
196 * @param[in] y_t y 分量关于参数 t 的表达式
197 * @param[in] t 参数变量名称
198 * @return 曲率的符号表达式
199 */
201 const std::shared_ptr<SymbolicExpr>& x_t,
202 const std::shared_ptr<SymbolicExpr>& y_t, const std::string& t,
204
205/**
206 * @brief 使用默认计算上下文计算参数曲线曲率,并显式报告无效输入和零速度.
207 */
209 const std::shared_ptr<SymbolicExpr>& x_t,
210 const std::shared_ptr<SymbolicExpr>& y_t, const std::string& t);
211
212
213
214/**
215 * @brief 计算函数 y = f(x) 的拐点(二阶导数为零的点).
216 *
217 * @param[in] f 曲线函数表达式 f(x)
218 * @param[in] var 自变量名称
219 * @return 拐点的 x 坐标列表
220 */
222 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
224
225/**
226 * @brief 使用默认计算上下文计算拐点,并显式报告无效输入.
227 */
229 const std::shared_ptr<SymbolicExpr>& f, const std::string& var);
230
231
232
233/**
234 * @brief 计算曲线 y = f(x) 绕 x 轴旋转所得旋转面的面积
235 *
236 * 公式: S = 2pi integralₐᵇ |f(x)| * sqrt(1 + f'(x)^2) dx
237 * Checked API 只接受可精确求值的符号定积分;超出支持域返回
238 * `CasErrc::Inconclusive`.
239 */
241 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
242 const std::shared_ptr<SymbolicExpr>& a, const std::shared_ptr<SymbolicExpr>& b,
244
245/**
246 * @brief 使用默认计算上下文计算绕 x 轴旋转面积,并显式报告失败语义.
247 */
249 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
250 const std::shared_ptr<SymbolicExpr>& a, const std::shared_ptr<SymbolicExpr>& b);
251
252/**
253 * @brief 计算曲线 y = f(x) 绕 x 轴旋转所得旋转面的面积.
254 *
255 * The convenience overload 先尝试符号积分,若失败则回退到数值积分.
256 *
257 * @param[in] f 曲线函数表达式 f(x)
258 * @param[in] var 自变量名称
259 * @param[in] a 积分下限
260 * @param[in] b 积分上限
261 * @return 旋转面面积的符号表达式
262 */
263
264/**
265 * @brief 计算曲线 y = f(x) 绕 y 轴旋转所得旋转面的面积
266 *
267 * 公式: S = 2pi integralₐᵇ |x| * sqrt(1 + f'(x)^2) dx
268 * Checked API 只接受可精确求值的符号定积分;超出支持域返回
269 * `CasErrc::Inconclusive`.
270 */
272 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
273 const std::shared_ptr<SymbolicExpr>& a, const std::shared_ptr<SymbolicExpr>& b,
275
276/**
277 * @brief 使用默认计算上下文计算绕 y 轴旋转面积,并显式报告失败语义.
278 */
280 const std::shared_ptr<SymbolicExpr>& f, const std::string& var,
281 const std::shared_ptr<SymbolicExpr>& a, const std::shared_ptr<SymbolicExpr>& b);
282
283/**
284 * @brief 计算曲线 y = f(x) 绕 y 轴旋转所得旋转面的面积.
285 *
286 * The convenience overload 先尝试符号积分,若失败则回退到数值积分.
287 *
288 * @param[in] f 曲线函数表达式 f(x)
289 * @param[in] var 自变量名称
290 * @param[in] a 积分下限
291 * @param[in] b 积分上限
292 * @return 旋转面面积的符号表达式
293 */
294
295} // namespace LMCAS
#define LMCAS_API
const std::string const LimitExprPtr & point
std::vector< std::pair< std::shared_ptr< SymbolicExpr >, std::string > > total_differential(const std::shared_ptr< SymbolicExpr > &f, const std::vector< std::string > &vars)
SymbolicExprVectorResult inverse_function_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &y, ComputationContext &context)
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
std::shared_ptr< SymbolicExpr > differential(const std::shared_ptr< SymbolicExpr > &f, const std::string &var)
__attribute__((visibility("default"))) VectorCalculusFieldResult gradient_checked(const std __attribute__((visibility("default"))) VectorCalculusFieldResult gradient_checked(const std __attribute__((visibility("default"))) VectorField gradient(const std const std::vector< std::string > & vars
AsymptoteAnalysisResult asymptotes_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, ComputationContext &context)
ContinuityResult continuity_at_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &point, ComputationContext &context)
ContinuityType
连续性类型枚举.
@ Jump
跳跃间断点:左极限 != 右极限,但两侧极限均存在
@ Continuous
连续:左极限 = 右极限 = 函数值
@ Essential
本性间断点:至少一侧极限不存在或为无穷
@ Removable
可去间断点:左极限 = 右极限 != 函数值(或函数无定义)
Result< ContinuityType > ContinuityResult
const MultiPoly & b
Result< std::shared_ptr< SymbolicExpr > > ExpressionResult
Result of an operation that produces a symbolic expression.
SymbolicExprVectorResult inflection_points_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, ComputationContext &context)
Result< std::vector< std::shared_ptr< SymbolicExpr > > > SymbolicExprVectorResult
ExpressionResult inverse_derivative_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &point, 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
ExpressionResult surface_area_revolution_y_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &a, const std::shared_ptr< SymbolicExpr > &b, ComputationContext &context)
Result< AsymptoteResult > AsymptoteAnalysisResult
std::shared_ptr< SymbolicExpr > log_differentiate(const std::shared_ptr< SymbolicExpr > &f, const std::string &var)
ExpressionResult curvature_parametric_checked(const std::shared_ptr< SymbolicExpr > &x_t, const std::shared_ptr< SymbolicExpr > &y_t, const std::string &t, ComputationContext &context)
ExpressionResult curvature_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, ComputationContext &context)
ExpressionResult surface_area_revolution_x_checked(const std::shared_ptr< SymbolicExpr > &f, const std::string &var, const std::shared_ptr< SymbolicExpr > &a, const std::shared_ptr< SymbolicExpr > &b, 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 & t
根据左右极限与函数值,在给定上下文假设下证明实数域中的连续性分类。 跳跃与可去间断的比较需证明逐点不等,相等性需保证各值有定义;形式非恒等不足以证明二者。 参数值或有定义性未确定时返回 Inconclu...
std::vector< std::pair< std::shared_ptr< SymbolicExpr >, std::shared_ptr< SymbolicExpr > > > oblique
斜渐近线 (斜率, 截距)
std::vector< std::shared_ptr< SymbolicExpr > > vertical
垂直渐近线 x = a
std::vector< std::shared_ptr< SymbolicExpr > > horizontal
水平渐近线 y = L
符号表达式主类 SymbolicExpr 及其工厂方法,运算接口.