YoushouldhavereceivedcopiesoftheGNUGeneralPublicLicenseandthe GNULesserGeneralPublicLicensealongwiththeGNUMPLibrary.Ifnot,
see https://www.gnu.org/licenses/. */
#include"gmp-impl.h" #include"longlong.h"
/* For input of size n, matrix elements are of size at most ceil(n/2)
- 1, but we need two limbs extra. */ void
mpn_hgcd_matrix_init (struct hgcd_matrix *M, mp_size_t n, mp_ptr p)
{
mp_size_t s = (n+1)/2 + 1;
M->alloc = s;
M->n = 1;
MPN_ZERO (p, 4 * s);
M->p[0][0] = p;
M->p[0][1] = p + s;
M->p[1][0] = p + 2 * s;
M->p[1][1] = p + 3 * s;
/* Multiply M by M1 from the right. Since the M1 elements fit in GMP_NUMB_BITS-1bits,Mgrowsbyatmostonelimb.Needs
temporary space M->n */ void
mpn_hgcd_matrix_mul_1 (struct hgcd_matrix *M, conststruct hgcd_matrix1 *M1,
mp_ptr tp)
{
mp_size_t n0, n1;
/* Could avoid copy by some swapping of pointers. */
MPN_COPY (tp, M->p[0][0], M->n);
n0 = mpn_hgcd_mul_matrix1_vector (M1, M->p[0][0], tp, M->p[0][1], M->n);
MPN_COPY (tp, M->p[1][0], M->n);
n1 = mpn_hgcd_mul_matrix1_vector (M1, M->p[1][0], tp, M->p[1][1], M->n);
/* Depends on zero initialization */
M->n = MAX(n0, n1);
ASSERT (M->n < M->alloc);
}
/* Multiply M by M1 from the right. Needs 3*(M->n + M1->n) + 5 limbs
of temporary storage (see mpn_matrix22_mul_itch). */ void
mpn_hgcd_matrix_mul (struct hgcd_matrix *M, conststruct hgcd_matrix *M1,
mp_ptr tp)
{
mp_size_t n;
/* About the new size of M:s elements. Since M1's diagonal elements are>0,noelementcandecrease.Thenewelementsareofsize M->n+M1->n,onelimbmoreorless.Thecomputationofthe matrixproductproduceselementsofsizeM->n+M1->n+1.But thetruesize,afternormalization,maybethreelimbssmaller.
Thereasonthattheproducthasnormalizedsize>=M->n+M1->n- 2issubtle.ItdependsonthefactthatMandM1canbefactored asproductsof(1,1;0,1)and(1,0;1,1),andthatwecan'thave MendingwithalargepowerandM1startingwithalargepowerof
the same matrix. */
/* FIXME: Strassen multiplication gives only a small speedup. In FFT multiplicationrange,thisfunctioncouldbespedupquitealot
using invariance. */
ASSERT (M->n + M1->n < M->alloc);
/* Multiplies the least significant p limbs of (a;b) by M^-1.
Temporary space needed: 2 * (p + M->n)*/
mp_size_t
mpn_hgcd_matrix_adjust (conststruct hgcd_matrix *M,
mp_size_t n, mp_ptr ap, mp_ptr bp,
mp_size_t p, mp_ptr tp)
{ /* M^-1 (a;b) = (r11, -r01; -r10, r00) (a ; b)
= (r11 a - r01 b; - r10 a + r00 b */
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.