LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
exact_factorization.hpp
浏览该文件的文档.
1#pragma once
2
3#include "polynomial.hpp"
5#include "bigint.hpp"
6#include "rational.hpp"
7#include "result.hpp"
9#include <cstdint>
10#include <vector>
11
12namespace LMCAS {
13
14/** @brief Berlekamp 分解结果。 */
16 int64_t prime; /**< 使用的素数。 */
17 std::vector<Polynomial<ModInt>> factors; /**< 模 p 下的不可约因子。 */
18 int null_space_dim; /**< 零空间维度,等于不可约因子数。 */
19 std::vector<std::vector<int64_t>> null_space_basis; /**< 零空间基向量。 */
20
22};
23
24/**
25 * @brief Berlekamp 模素数分解(内部接口).
26 *
27 * 在有限域 F_p 上对有理系数多项式执行 Berlekamp 算法,
28 * 返回模 p 下的不可约因子列表.
29 *
30 * @param[in] poly 有理系数多项式
31 * @param[in] prime 选定的素数 p
32 * @return Berlekamp 分解结果
33 *
34 * @internal
35 */
36LMCAS_API BerlekampResult berlekamp_factor(
37 const Polynomial<Rational>& poly,
38 int64_t prime);
39
41
42/**
43 * @brief 执行 Hensel 提升并诊断前置条件。
44 * 空因子列表、非法素数、零或常数输入、零因子及模 p 因子乘积
45 * 与原多项式不符时,通过 CasError 返回具体诊断。
46 */
48 const Polynomial<BigInt>& poly,
49 const std::vector<Polynomial<ModInt>>& mod_factors,
50 int64_t prime,
52
55
56/**
57 * @brief 在计算预算内执行精确 Zassenhaus 因子组合。
58 * 要求重构模数为正,且提升因子乘积与 @p poly 的整数归一化结果同余。
59 * 候选子集按字典序枚举,支持任意因子数;预算耗尽时以 Inconclusive 返回精确部分分解。
60 */
62 const Polynomial<Rational>& poly,
66
68 const Polynomial<Rational>& poly,
69 const std::vector<Polynomial<BigInt>>& lifted_factors,
70 const BigInt& reconstruction_modulus);
71
72/**
73 * @brief 二因子二次 Hensel 提升的状态结构.
74 *
75 * 存储一对因子 g, h 及其 Bezout 系数 s, t,满足:
76 * - f == g * h (mod modulus)
77 * - s * g + t * h == 1 (mod modulus)
78 *
79 * 系数按升幂存储:coeffs[i] 对应 x^i 的系数.
80 */
82 std::vector<BigInt> g; /**< 第一个因子的系数。 */
83 std::vector<BigInt> h; /**< 第二个因子的系数。 */
84 std::vector<BigInt> s; /**< g 的 Bezout 系数。 */
85 std::vector<BigInt> t; /**< h 的 Bezout 系数。 */
86 BigInt modulus; /**< 当前模数。 */
87};
88
89/**
90 * @brief 执行一步二次 Hensel 提升:mod m -> mod m^2.
91 *
92 * 给定 f == g*h (mod m) 且 s*g + t*h == 1 (mod m),
93 * 计算 g', h', s', t' 使得 f == g'*h' (mod m^2) 且 s'*g' + t'*h' == 1 (mod m^2).
94 *
95 * @param[in] f 原始多项式系数向量(升幂排列)
96 * @param[in] current 当前提升状态(g, h, s, t, modulus=m)
97 * @return 提升后的状态(g', h', s', t', modulus=m^2)
98 *
99 * @pre f == g*h (mod m)
100 * @pre s*g + t*h == 1 (mod m)
101 * @pre deg(s) < deg(h), deg(t) < deg(g)
102 *
103 * @see Zassenhaus, H. "On Hensel factorization, I."
104 * Journal of Number Theory, 1(3), 1969.
105 */
107 const std::vector<BigInt>& f,
108 const HenselLiftPair& current);
109
110/** @brief 无平方因子预处理结果。 */
112 Polynomial<Rational> square_free; /**< 无平方因子部分。 */
113 Polynomial<Rational> repeated_factor; /**< 重复因子 gcd(f, f')。 */
114 bool had_repeated_factors; /**< 是否存在重复因子。 */
115
117};
118
119/**
120 * @brief 计算多项式的无平方因子部分.
121 *
122 * 以 gcd(f, f') 分离重复因子,为 Berlekamp 分解提供无平方因子部分。
123 *
124 * @param[in] poly 输入的有理系数多项式
125 * @return 无平方因子预处理结果,包含 square-free 部分和重复因子信息
126 *
127 * @internal
128 */
129LMCAS_API TfSquareFreeResult tf_square_free(const Polynomial<Rational>& poly);
130
131}
任意精度整数 BigInt,底层调用 LMMP 实现高性能大数运算。
一元多项式模板类
#define LMCAS_API
模运算工具:ModInt 类、扩展欧几里得、CRT、有理重构。
TfSquareFreeResult tf_square_free(const Polynomial< Rational > &poly)
计算多项式的无平方因子部分,用于 Berlekamp 模分解预处理。
const std::vector< Polynomial< BigInt > > const BigInt ComputationContext & context
std::vector< BigInt > g
第一个因子的系数。
HenselLiftResult hensel_lift_checked(const Polynomial< BigInt > &poly, const std::vector< Polynomial< ModInt > > &mod_factors, int64_t prime, int lift_bound)
Hensel 提升:将模 p 因子提升到 mod p^k.
BerlekampResult berlekamp_factor(const Polynomial< Rational > &poly, int64_t prime)
const std::vector< Polynomial< BigInt > > const BigInt & reconstruction_modulus
Result< std::vector< Polynomial< BigInt > > > HenselLiftResult
const std::vector< Polynomial< BigInt > > & lifted_factors
HenselLiftPair hl_two_factor_lift(const std::vector< BigInt > &f, const HenselLiftPair &current)
执行一步二次 Hensel 提升:mod m -> mod m^2.
std::vector< BigInt > t
h 的 Bezout 系数。
const std::vector< Polynomial< ModInt > > & mod_factors
std::vector< BigInt > h
第二个因子的系数。
std::vector< BigInt > s
g 的 Bezout 系数。
Result< MathResult< std::vector< Polynomial< Rational > > > > ZassenhausResult
ZassenhausResult zassenhaus_combine_checked(const Polynomial< Rational > &poly, const std::vector< Polynomial< BigInt > > &lifted_factors, const BigInt &reconstruction_modulus, ComputationContext &context)
const std::vector< Polynomial< ModInt > > int64_t int lift_bound
二因子二次 Hensel 提升的状态结构.
一元多项式模板类 Polynomial<T>,支持四则运算,GCD,求导,求值.
精确有理数 Rational,基于 BigInt 分子/分母表示,自动约分。
int null_space_dim
零空间维度,等于不可约因子数。
std::vector< std::vector< int64_t > > null_space_basis
零空间基向量。
std::vector< Polynomial< ModInt > > factors
模 p 下的不可约因子。
int64_t prime
使用的素数。
Polynomial< Rational > square_free
无平方因子部分。
Polynomial< Rational > repeated_factor
重复因子 gcd(f, f')。
bool had_repeated_factors
是否存在重复因子。