LMCAS
Lamina Computer Algebra System
Toggle main menu visibility
载入中...
搜索中...
未找到
transcendental_factor.hpp
浏览该文件的文档.
1
/**
2
* @file transcendental_factor.hpp
3
* @brief 混合超越方程不可约因式分解器公共 API.
4
*
5
* 将 Berlekamp/Zassenhaus 风格的因式分解算法从纯多项式域推广到含超越函数的
6
* 表达式空间.核心流程:换元 -> 多项式构造 -> 模分解 -> Hensel 提升 -> 因子组合 -> 逆换元.
7
*/
8
#pragma once
9
10
#include "
computation_context.hpp
"
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
20
namespace
LMCAS
{
21
22
/// 换元映射条目:超越子表达式 -> 代数不定元名
23
struct
TransSubstitution
{
24
std::shared_ptr<SymbolicExpr>
trans_expr
;
///< 原始超越子表达式 (e.g., sin(x))
25
std::string
indeterminate
;
///< 代数不定元名 (e.g., "u0")
26
};
27
28
/// 换元结果
29
struct
TransSubstitutionResult
{
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
*/
46
LMCAS_API
Result<std::vector<std::shared_ptr<SymbolicExpr>
>>
factor_transcendental
(
47
const
std::shared_ptr<SymbolicExpr>& expr,
48
const
std::string& var,
49
ComputationContext
&
context
);
50
51
LMCAS_API
Result<std::vector<std::shared_ptr<SymbolicExpr>
>>
factor_transcendental
(
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
*/
65
LMCAS_API
TransSubstitutionResult
detect_trans_substitutions
(
66
const
std::shared_ptr<SymbolicExpr>& expr,
67
const
std::string& var);
68
69
70
/// 多项式构造结果
71
struct
TfPolyBuildResult
{
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
*/
94
LMCAS_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
*/
110
LMCAS_API
std::vector<std::shared_ptr<SymbolicExpr>>
tf_simplify_factors
(
111
std::vector<std::shared_ptr<SymbolicExpr>>& factors);
112
113
}
// namespace LMCAS
LMCAS::ComputationContext
定义
computation_context.hpp:99
LMCAS::Polynomial
一元多项式模板类
定义
polynomial.hpp:52
LMCAS::Result
定义
result.hpp:39
computation_context.hpp
LMCAS_API
#define LMCAS_API
定义
lmcas_export.hpp:13
LMCAS
定义
assumption.hpp:11
LMCAS::context
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
定义
exact_factorization.hpp:65
LMCAS::TransSubstitutionResult::poly_expr
std::shared_ptr< SymbolicExpr > poly_expr
换元后的多项式表达式
定义
transcendental_factor.hpp:31
LMCAS::tf_simplify_factors
std::vector< std::shared_ptr< SymbolicExpr > > tf_simplify_factors(std::vector< std::shared_ptr< SymbolicExpr > > &factors)
化简逆换元后的因子,合并数值因子及乘积的数值前导系数。 保留非常数部分,将非 1 的常数积置于结果首位。
定义
transcendental_rewrite.cpp:167
LMCAS::factor_transcendental
Result< std::vector< std::shared_ptr< SymbolicExpr > > > factor_transcendental(const std::shared_ptr< SymbolicExpr > &expr, const std::string &var, ComputationContext &context)
定义
transcendental_factor.cpp:88
LMCAS::TransSubstitution::indeterminate
std::string indeterminate
代数不定元名 (e.g., "u0")
定义
transcendental_factor.hpp:25
LMCAS::detect_trans_substitutions
TransSubstitutionResult detect_trans_substitutions(const std::shared_ptr< SymbolicExpr > &expr, const std::string &var)
为依赖 var 的 Sin、Cos、Exp、Ln、Tan 子表达式构造换元结果。
定义
transcendental_substitution.cpp:264
LMCAS::TransSubstitution::trans_expr
std::shared_ptr< SymbolicExpr > trans_expr
原始超越子表达式 (e.g., sin(x))
定义
transcendental_factor.hpp:24
LMCAS::TransSubstitutionResult::mappings
std::vector< TransSubstitution > mappings
所有换元映射
定义
transcendental_factor.hpp:30
LMCAS::tf_build_polynomial
Result< TfPolyBuildResult > tf_build_polynomial(const std::shared_ptr< SymbolicExpr > &poly_expr, const std::vector< std::string > &indeterminates, const std::string &original_var)
定义
transcendental_polynomial.cpp:166
LMCAS::TransSubstitutionResult::constraints
std::vector< std::shared_ptr< SymbolicExpr > > constraints
代数约束 (e.g., u0^2+u1^2-1=0)
定义
transcendental_factor.hpp:32
LMCAS::TransSubstitutionResult
换元结果
定义
transcendental_factor.hpp:29
LMCAS::TransSubstitution
换元映射条目:超越子表达式 -> 代数不定元名
定义
transcendental_factor.hpp:23
polynomial.hpp
一元多项式模板类 Polynomial<T>,支持四则运算,GCD,求导,求值.
result.hpp
LMCAS::TfPolyBuildResult::param_variables
std::vector< std::string > param_variables
参数变量列表(非主变量的不定元)
定义
transcendental_factor.hpp:75
LMCAS::TfPolyBuildResult::poly
Polynomial< Rational > poly
主变量多项式(单变量或主变量策略)
定义
transcendental_factor.hpp:73
LMCAS::TfPolyBuildResult::TfPolyBuildResult
TfPolyBuildResult()
定义
transcendental_factor.hpp:77
LMCAS::TfPolyBuildResult::main_variable
std::string main_variable
选定的主变量名
定义
transcendental_factor.hpp:74
LMCAS::TfPolyBuildResult::success
bool success
转换是否成功
定义
transcendental_factor.hpp:72
symbolic.hpp
符号表达式主类 SymbolicExpr 及其工厂方法,运算接口.
include
transcendental_factor.hpp
生成于
, 为 LMCAS使用
1.18.0