Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions flint-extras/src/nmod_poly_mat_approximant.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,28 @@ void nmod_poly_mat_mbasis(nmod_poly_mat_t appbas,

// TODO doc
// TODO middle_product currently naive


void nmod_poly_mat_pmbasis_old(nmod_poly_mat_t appbas,
slong * shift,
const nmod_poly_mat_t pmat,
slong order);

void nmod_poly_mat_pmbasis(nmod_poly_mat_t appbas,
slong * shift,
const nmod_poly_mat_t pmat,
slong order);

/** Using geometric matrix product for the partial bases
* and linearises the product residual x basis
*/

void nmod_poly_mat_pmbasis_geometric(nmod_poly_mat_t appbas,
slong * shift,
const nmod_poly_mat_t pmat,
slong order);



/** Computes a `shift`-Popov approximant basis for `(pmat,order)` using the
* algorithm PM-Basis (see @ref pmbasis) twice: the first call yields an
Expand Down
76 changes: 75 additions & 1 deletion flint-extras/src/nmod_poly_mat_extra/approximant_basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void nmod_poly_mat_mbasis(nmod_poly_mat_t appbas,
nmod_mat_poly_clear(app);
}

void nmod_poly_mat_pmbasis(nmod_poly_mat_t appbas,
void nmod_poly_mat_pmbasis_old(nmod_poly_mat_t appbas,
slong * shift,
const nmod_poly_mat_t pmat,
slong order)
Expand All @@ -48,6 +48,42 @@ void nmod_poly_mat_pmbasis(nmod_poly_mat_t appbas,
nmod_poly_mat_init(appbas2, pmat->r, pmat->r, pmat->modulus);
nmod_poly_mat_init(residual, pmat->r, pmat->c, pmat->modulus);

nmod_poly_mat_pmbasis_old(appbas, shift, pmat, order1);

nmod_poly_mat_middle_product_naive_old(residual, appbas, pmat, order1, order2-1);

nmod_poly_mat_pmbasis_old(appbas2, shift, residual, order2);

nmod_poly_mat_mul(appbas, appbas2, appbas);

nmod_poly_mat_clear(appbas2);
nmod_poly_mat_clear(residual);
}

void nmod_poly_mat_pmbasis(nmod_poly_mat_t appbas,
slong * shift,
const nmod_poly_mat_t ipmat,
slong order)
{

nmod_poly_mat_t pmat;

nmod_poly_mat_init(pmat, ipmat->r, ipmat->c, ipmat->modulus);
nmod_poly_mat_set_trunc(pmat,ipmat,order);

if (order <= PMBASIS_THRES)
{
nmod_poly_mat_mbasis(appbas, shift, pmat, order);
return;
}

const long order1 = order>>1;
const long order2 = order - order1;
nmod_poly_mat_t appbas2, residual;

nmod_poly_mat_init(appbas2, pmat->r, pmat->r, pmat->modulus);
nmod_poly_mat_init(residual, pmat->r, pmat->c, pmat->modulus);

nmod_poly_mat_pmbasis(appbas, shift, pmat, order1);

nmod_poly_mat_middle_product_naive(residual, appbas, pmat, order1, order2-1);
Expand All @@ -59,3 +95,41 @@ void nmod_poly_mat_pmbasis(nmod_poly_mat_t appbas,
nmod_poly_mat_clear(appbas2);
nmod_poly_mat_clear(residual);
}

void nmod_poly_mat_pmbasis_geometric(nmod_poly_mat_t appbas,
slong * shift,
const nmod_poly_mat_t ipmat,
slong order)
{

nmod_poly_mat_t pmat;

nmod_poly_mat_init(pmat, ipmat->r, ipmat->c, ipmat->modulus);
nmod_poly_mat_set_trunc(pmat,ipmat,order);

if (order <= PMBASIS_THRES)
{
nmod_poly_mat_mbasis(appbas, shift, pmat, order);
return;
}

const long order1 = order>>1;
const long order2 = order - order1;
nmod_poly_mat_t appbas2, residual;

nmod_poly_mat_init(appbas2, pmat->r, pmat->r, pmat->modulus);
nmod_poly_mat_init(residual, pmat->r, pmat->c, pmat->modulus);

nmod_poly_mat_pmbasis_geometric(appbas, shift, pmat, order1);

nmod_poly_mat_middle_product_naive(residual, appbas, pmat, order1, order2-1);

nmod_poly_mat_pmbasis_geometric(appbas2, shift, residual, order2);

nmod_poly_mat_mul_geometric(appbas, appbas2, appbas);

nmod_poly_mat_clear(appbas2);
nmod_poly_mat_clear(residual);
}


26 changes: 25 additions & 1 deletion flint-extras/src/nmod_poly_mat_extra/middle_product.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* output can alias input
* naive implementation (multiply, shift, truncate)
*/
void nmod_poly_mat_middle_product_naive(nmod_poly_mat_t C, const nmod_poly_mat_t A, const nmod_poly_mat_t B,
void nmod_poly_mat_middle_product_naive_old(nmod_poly_mat_t C, const nmod_poly_mat_t A, const nmod_poly_mat_t B,
const ulong dA, const ulong dB)
{
nmod_poly_mat_mul(C, A, B);
Expand All @@ -31,6 +31,30 @@ void nmod_poly_mat_middle_product_naive(nmod_poly_mat_t C, const nmod_poly_mat_t
}


/** Middle product for polynomial matrices
* sets C = ((A * B) div x^d1) mod x^(d2+1), assuming deg(A) <= d1 and deg(B) <= d1 + d2
* output can alias input
* naive implementation (multiply, shift, truncate)
*/

void nmod_poly_mat_middle_product_naive(nmod_poly_mat_t C, const nmod_poly_mat_t A,\
const nmod_poly_mat_t B, const ulong d1, const ulong d2)
{
slong degA;
degA=nmod_poly_mat_degree(A);

nmod_poly_mat_t BT;
nmod_poly_mat_init(BT, A->c, B->c, B->modulus);
nmod_poly_mat_shift_right(BT, B, d1-degA); // No aliasing specified for that?

nmod_poly_mat_mul(C,A,BT);
nmod_poly_mat_shift_right(C, C, degA);
nmod_poly_mat_truncate(C, d2+1);

nmod_poly_mat_clear(BT);
}


/** Middle product for polynomial matrices
* sets C = ((A * B) div x^dA) mod x^(dB+1)
* output can alias input
Expand Down
10 changes: 10 additions & 0 deletions flint-extras/src/nmod_poly_mat_multiply.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@ void nmod_poly_mat_mul_waksman(nmod_poly_mat_t C, const nmod_poly_mat_t A, cons
* output can alias input
* naive implementation (multiply, shift, truncate)
*/
void nmod_poly_mat_middle_product_naive_old(nmod_poly_mat_t C, const nmod_poly_mat_t A, const nmod_poly_mat_t B,
const ulong dA, const ulong dB);


/** Middle product for polynomial matrices
* sets C = ((A * B) div x^d1) mod x^(d2+1), assuming deg(A) <= d1 and deg(B) <= d1 + d2
* output can alias input
* naive implementation (multiply, shift, truncate)
*/
void nmod_poly_mat_middle_product_naive(nmod_poly_mat_t C, const nmod_poly_mat_t A, const nmod_poly_mat_t B,
const ulong dA, const ulong dB);


/** Middle product for polynomial matrices
* sets C = ((A * B) div x^dA) mod x^(dB+1)
* output can alias input
Expand Down