LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
exact_root_id.hpp
浏览该文件的文档.
1#pragma once
2
3#include "polynomial.hpp"
4#include <algorithm>
5
6#include <cstddef>
7
8namespace LMCAS::detail {
9
12 std::size_t index = 0;
13
14 std::size_t hash() const {
15 std::size_t seed = index;
16 for (const auto& coefficient : polynomial.coeffs) {
17 seed ^= coefficient.hash() + 0x9e3779b9U +
18 (seed << 6U) + (seed >> 2U);
19 }
20 return seed;
21 }
22
23 int compare(const ExactRootId& other) const {
24 const auto common = std::min(
25 polynomial.coeffs.size(), other.polynomial.coeffs.size());
26 for (std::size_t position = common; position-- > 0;) {
27 const auto& left = polynomial.coeffs[position];
28 const auto& right = other.polynomial.coeffs[position];
29 if (left < right) return -1;
30 if (right < left) return 1;
31 }
32 if (polynomial.coeffs.size() != other.polynomial.coeffs.size()) {
33 return polynomial.coeffs.size() < other.polynomial.coeffs.size()
34 ? -1 : 1;
35 }
36 if (index == other.index) return 0;
37 return index < other.index ? -1 : 1;
38 }
39};
40
41}
一元多项式模板类
std::vector< CoeffType > coeffs
系数数组,coeffs[i] 为 x^i 的系数
多元 Hensel 提升(单变量步)
const ExprPtr & right
一元多项式模板类 Polynomial<T>,支持四则运算,GCD,求导,求值.
Polynomial< Rational > polynomial
int compare(const ExactRootId &other) const