This file is part of LMMP.
LMMP is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library. If not, see https://www.gnu.org/licenses/.
36 {
37
38 const size_t CAP = 2048;
39 mp_ptr e = alloc_limbs(CAP), f1 = alloc_limbs(CAP), f2 = alloc_limbs(CAP),
40 prod = alloc_limbs(CAP);
41 const ulong n_values[] = {0, 1, 5, 10, 20, 50, 100};
42 for (
size_t n_index = 0; n_index <
ARRAY_SIZE(n_values); ++n_index) {
43 ulong n = n_values[n_index];
44 for (
ulong r = 0; r <=
n; r += (
n > 20 ? 20 : 1)) {
45
46 e[0] = 1;
48 for (
u32 i = (
u32)(
n - r + 1); i <=
n; ++i) elen = chain_mul_small(e, elen, i, CAP);
49
52 mp_ptr dst = alloc_limbs(need + 2);
56
57
58 if (r >= 2 &&
n - r >= 1) {
65 mp_size_t l1 = norm_len(f1, need1 + 2), l2 = norm_len(f2, need2 + 2);
67 mul_sorted(
prod, dst, ldst, f2, l2);
70 }
72 }
73 }
74
75
76 {
77 struct known_result {
u32 n;
u32 r;
u64 v; } known[] = {{10, 5, 252ull}, {52, 5, 2598960ull}};
78 for (
size_t k_index = 0; k_index <
ARRAY_SIZE(known); ++k_index) {
79 const struct known_result
k = known[k_index];
82 mp_ptr dst = alloc_limbs(need + 2);
88 }
89 }
90 mp_ptr cn = alloc_limbs(CAP), cn1 = alloc_limbs(CAP), cn2 = alloc_limbs(CAP);
91 const u32 n_values2[] = {2, 5, 10, 20, 50};
92 for (
size_t n_index = 0; n_index <
ARRAY_SIZE(n_values2); ++n_index) {
93 u32 n = n_values2[n_index];
94 for (
u32 r = 1; r <=
n / 2; ++r) {
101 if (nd2) {
102
106 mp_size_t l1 = norm_len(cn1, nd1 + 2), l2 = norm_len(cn2, nd2 + 2);
107
108 mp_ptr pad = alloc_limbs(CAP), sum = alloc_limbs(CAP);
109 size_t mx = (size_t)(l1 > l2 ? l1 : l2) + 1;
111 memcpy(pad, cn1, (size_t)l1 * 8);
113 memcpy(sum, cn2, (size_t)l2 * 8);
115 TEST_CHECK(mpn_eq(sum, mx, cn, norm_len(cn, nd0 + 2)));
118 }
119
120
129 mp_ptr rem = alloc_limbs(nfn + 2);
132 mp_size_t lfr = norm_len(f1, nfr + 2), lfnr = norm_len(f2, nfnr + 2);
133 mp_size_t lcn = norm_len(cn, nd0 + 2), lfn = norm_len(rem, nfn + 2);
134 mp_ptr quot = alloc_limbs(CAP);
135 mul_sorted(
prod, cn, lcn, f1, lfr);
137 mul_sorted(quot,
prod, lp, f2, lfnr);
138 lp = norm_len(quot, lp + lfnr);
142 }
143 }
144 }
146
147
148
149 {
155 mp_ptr dst = alloc_limbs(need + 2);
161 }
162
163
164 const u32 x_values[] = {1, 3, 10};
165 for (
size_t x_index = 0; x_index <
ARRAY_SIZE(x_values); ++x_index) {
166 u32 x = x_values[x_index];
167 const u32 m_values[] = {2, 5, 10};
168 for (
size_t m_index = 0; m_index <
ARRAY_SIZE(m_values); ++m_index) {
169 u32 m = m_values[m_index];
170 const u32 n_values3[] = {1, 3, 10};
171 for (
size_t n_index = 0; n_index <
ARRAY_SIZE(n_values3); ++n_index) {
172 u32 n = n_values3[n_index];
173 if ((
u64)x + (
u64)
n * m > 100000)
continue;
174 e[0] = 1;
176 for (
u32 i = 0; i <=
n; ++i) elen = chain_mul_small(e, elen, x + i * m, CAP);
178 mp_ptr dst = alloc_limbs(need + 2);
183 }
184 }
185 }
187}
#define lmmp_zero(dst, n)
void lmmp_free(void *ptr)
内存释放函数(调用lmmp_heap_free_fn)
mp_limb_t u64
Copyright (C) 2026 HJimmyK (Jericho Knox)
mp_limb_t lmmp_add_n_(mp_ptr dst, mp_srcptr numa, mp_srcptr numb, mp_size_t n)
无进位的n位加法 [dst,n] = [numa,n] + [numb,n]
mp_size_t lmmp_multinomial_size_(const uintp r, uint m, ulong *n)
计算多项式系数的 limb 缓冲区长度
mp_size_t lmmp_arith_seqprod_size_(uint x, uint n, uint m)
计算等差数列乘积 x(x+m)...(x+n*m)的 limb 缓冲区长度
mp_size_t lmmp_factorial_size_(uint n, mp_bitcnt_t *bits)
计算 n!
mp_size_t lmmp_factorial_(mp_ptr dst, mp_bitcnt_t bits, mp_size_t rn, uint n)
计算 n!
mp_size_t lmmp_nCr_size_(uint n, uint r, mp_bitcnt_t *bits)
计算 nCr 组合数的 limb 缓冲区长度
mp_size_t lmmp_nCr_(mp_ptr dst, mp_bitcnt_t bits, mp_size_t rn, uint n, uint r)
计算 nCr 组合数 ( nCr = n!
mp_size_t lmmp_nPr_size_(ulong n, ulong r, mp_bitcnt_t *bits)
计算 nPr 排列数的 limb 缓冲区长度
mp_size_t lmmp_multinomial_(mp_ptr dst, mp_size_t rn, uint n, const uintp r, uint m)
计算多项式系数
mp_size_t lmmp_arith_seqprod_(mp_ptr dst, mp_size_t rn, uint x, uint n, uint m)
计算等差数列乘积 x(x+m)...(x+n*m)
mp_size_t lmmp_nPr_(mp_ptr dst, mp_bitcnt_t bits, mp_size_t rn, ulong n, ulong r)
计算 nPr 排列数 ( nPr = n!
#define ARRAY_SIZE(a)
Copyright (C) 2026 HJimmyK (Jericho Knox)
#define TEST_CHECK_EQ(a, b)