8 static struct binom binom
;
10 Value
*binomial(unsigned n
, unsigned k
)
15 return &binom
.binom
[n
]->p
[k
];
17 if (n
>= binom
.size
) {
18 int size
= 3*(n
+ 5)/2;
20 binom
.binom
= (Vector
**)realloc(binom
.binom
, size
*sizeof(Vector
*));
23 for (i
= binom
.n
; i
<= n
; ++i
) {
24 binom
.binom
[i
] = Vector_Alloc(i
+1);
26 value_set_si(binom
.binom
[0]->p
[0], 1);
28 value_set_si(binom
.binom
[i
]->p
[0], 1);
29 value_set_si(binom
.binom
[i
]->p
[i
], 1);
30 for (j
= 1; j
< i
; ++j
)
31 value_addto(binom
.binom
[i
]->p
[j
],
32 binom
.binom
[i
-1]->p
[j
-1], binom
.binom
[i
-1]->p
[j
]);
36 return &binom
.binom
[n
]->p
[k
];
44 static struct fact fact
;
46 Value
*factorial(unsigned n
)
54 int size
= 3*(n
+ 5)/2;
56 fact
.fact
= (Value
*)realloc(fact
.fact
, size
*sizeof(Value
));
59 for (i
= fact
.n
; i
<= n
; ++i
) {
60 value_init(fact
.fact
[i
]);
62 value_set_si(fact
.fact
[0], 1);
64 mpz_mul_ui(fact
.fact
[i
], fact
.fact
[i
-1], i
);