LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
transcendental_factor.hpp
浏览该文件的文档.
1/**
2 * @file transcendental_factor.hpp
3 * @brief 混合超越方程不可约因式分解器公共 API.
4 *
5 * 将 Berlekamp/Zassenhaus 风格的因式分解算法从纯多项式域推广到含超越函数的
6 * 表达式空间.核心流程:换元 -> 多项式构造 -> 模分解 -> Hensel 提升 -> 因子组合 -> 逆换元.
7 */
8#pragma once
9
11#include "polynomial.hpp"
12#include "result.hpp"
13#include "symbolic.hpp"
14
15#include <memory>
16#include <string>
17#include <vector>
18#include <cstdint>
19
20namespace LMCAS {
21
22/// 换元映射条目:超越子表达式 -> 代数不定元名
24 std::shared_ptr<SymbolicExpr> trans_expr; ///< 原始超越子表达式 (e.g., sin(x))
25 std::string indeterminate; ///< 代数不定元名 (e.g., "u0")
26};
27
28/// 换元结果
30 std::vector<TransSubstitution> mappings; ///< 所有换元映射
31 std::shared_ptr<SymbolicExpr> poly_expr; ///< 换元后的多项式表达式
32 std::vector<std::shared_ptr<SymbolicExpr>> constraints; ///< 代数约束 (e.g., u0^2+u1^2-1=0)
33};
34
35
36/**
37 * @brief 分解含 sin、cos、exp、ln 等超越函数的表达式。
38 *
39 * 不支持的转换保留原表达式;资源限制、取消和内部错误通过 Result 传播。
40 *
41 * @param[in] expr 待分解的符号表达式
42 * @param[in] var 目标变量名
43 * @param[in,out] context 共享计算预算和取消状态
44 * @return 不可约因子的列表(乘积等于原表达式,可能含常数因子)
45 */
47 const std::shared_ptr<SymbolicExpr>& expr,
48 const std::string& var,
50
52 const std::shared_ptr<SymbolicExpr>& expr,
53 const std::string& var);
54
55/**
56 * @brief 检测表达式中的超越函数换元模式.
57 *
58 * 遍历表达式 AST,识别所有依赖目标变量的超越子表达式,为每个分配代数不定元,
59 * 并记录不定元之间的代数约束(如三角恒等式 u_sin^2 + u_cos^2 = 1).
60 *
61 * @param[in] expr 待检测的符号表达式
62 * @param[in] var 目标变量名
63 * @return 换元结果,包含映射表,换元后多项式表达式及约束列表
64 */
66 const std::shared_ptr<SymbolicExpr>& expr,
67 const std::string& var);
68
69
70/// 多项式构造结果
72 bool success; ///< 转换是否成功
73 Polynomial<Rational> poly; ///< 主变量多项式(单变量或主变量策略)
74 std::string main_variable; ///< 选定的主变量名
75 std::vector<std::string> param_variables; ///< 参数变量列表(非主变量的不定元)
76
77 TfPolyBuildResult() : success(false), poly("x") {}
78};
79
80/**
81 * @brief 将换元后的表达式构造为有理系数多项式。
82 *
83 * 选择次数最高的不定元为主变量,经 symbolic_to_poly 转为 Polynomial<Rational>。
84 * 非主变量系数须可表示为有理数,否则转换失败,保持系数完整并以错误区别于零。
85 * success=false 仅表示策略不匹配;其他转换错误由外层 Result 原样传播。
86 *
87 * @param[in] poly_expr 换元后的符号表达式
88 * @param[in] indeterminates 不定元名称列表(如 {"u0", "u1"})
89 * @param[in] original_var 原始目标变量名(如 "x")
90 * @return 多项式构造结果
91 *
92 * @internal
93 */
94LMCAS_API Result<TfPolyBuildResult> tf_build_polynomial(
95 const std::shared_ptr<SymbolicExpr>& poly_expr,
96 const std::vector<std::string>& indeterminates,
97 const std::string& original_var);
98
99/**
100 * @brief 对逆换元后的因子列表执行化简与常数乘子提取.
101 *
102 * 对每个因子调用 simplify() 规范化,提取数值前导系数,
103 * 将所有常数乘子合并为单一数值因子.
104 *
105 * @param[in,out] factors 因子列表
106 * @return 化简后的因子列表(可能含首位常数因子)
107 *
108 * @internal
109 */
110LMCAS_API std::vector<std::shared_ptr<SymbolicExpr>> tf_simplify_factors(
111 std::vector<std::shared_ptr<SymbolicExpr>>& factors);
112
113} // namespace LMCAS
一元多项式模板类
#define LMCAS_API
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
std::shared_ptr< SymbolicExpr > poly_expr
换元后的多项式表达式
std::vector< std::shared_ptr< SymbolicExpr > > tf_simplify_factors(std::vector< std::shared_ptr< SymbolicExpr > > &factors)
化简逆换元后的因子,合并数值因子及乘积的数值前导系数。 保留非常数部分,将非 1 的常数积置于结果首位。
Result< std::vector< std::shared_ptr< SymbolicExpr > > > factor_transcendental(const std::shared_ptr< SymbolicExpr > &expr, const std::string &var, ComputationContext &context)
std::string indeterminate
代数不定元名 (e.g., "u0")
TransSubstitutionResult detect_trans_substitutions(const std::shared_ptr< SymbolicExpr > &expr, const std::string &var)
为依赖 var 的 Sin、Cos、Exp、Ln、Tan 子表达式构造换元结果。
std::shared_ptr< SymbolicExpr > trans_expr
原始超越子表达式 (e.g., sin(x))
std::vector< TransSubstitution > mappings
所有换元映射
Result< TfPolyBuildResult > tf_build_polynomial(const std::shared_ptr< SymbolicExpr > &poly_expr, const std::vector< std::string > &indeterminates, const std::string &original_var)
std::vector< std::shared_ptr< SymbolicExpr > > constraints
代数约束 (e.g., u0^2+u1^2-1=0)
换元映射条目:超越子表达式 -> 代数不定元名
一元多项式模板类 Polynomial<T>,支持四则运算,GCD,求导,求值.
std::vector< std::string > param_variables
参数变量列表(非主变量的不定元)
Polynomial< Rational > poly
主变量多项式(单变量或主变量策略)
std::string main_variable
选定的主变量名
符号表达式主类 SymbolicExpr 及其工厂方法,运算接口.