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
21 changes: 18 additions & 3 deletions src/fmpz_mat/minpoly_modular.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static slong _fmpz_mat_minpoly_small(fmpz * rop, const fmpz_mat_t op)
static void _fmpz_mat_bound_ovals_of_cassini(fmpz_t b, const fmpz_mat_t op)
{
slong n = op->r, i, j;
fmpz * v1;
fmpz * v1, * v2;
fmpz_t t, q, r1, r2;

fmpz_init(t);
Expand All @@ -51,6 +51,7 @@ static void _fmpz_mat_bound_ovals_of_cassini(fmpz_t b, const fmpz_mat_t op)
fmpz_init(r2);

v1 = _fmpz_vec_init(n);
v2 = _fmpz_vec_init(n);

/* |A| [1,1,...,1]^T */
for (i = 0; i < n; i++)
Expand All @@ -63,13 +64,27 @@ static void _fmpz_mat_bound_ovals_of_cassini(fmpz_t b, const fmpz_mat_t op)
fmpz_sub(v1 + i, v1 + i, fmpz_mat_entry(op, i, j));
}
}
/* |A|^t * |A| * [1,1,...,1]^T */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code doesn't seem to match the formula in the comment. It looks like v1[i] is being repeatedly multiplied by different matrix entries while the intended behavior is to repeatedly add products of different matrix entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch...I've tried again, with a better matrix vector product

for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
if (fmpz_sgn(fmpz_mat_entry(op, j, i)) >= 0)
fmpz_addmul(v2 + i, v1 + j, fmpz_mat_entry(op, j, i));
else
fmpz_submul(v2 + i, v1 + j, fmpz_mat_entry(op, j, i));
}
}

_fmpz_vec_clear(v1, n);
v1 = v2;

for (i = 0; i < n; i++)
{
fmpz_zero(t);

/* q_i */
fmpz_abs(t, fmpz_mat_entry(op, i, i));
for (j = 1; j < n; j++)
fmpz_addmul(t, fmpz_mat_entry(op, i, j), fmpz_mat_entry(op, i, j));

if (fmpz_cmp(t, q) > 0)
fmpz_set(q, t);
Expand Down
2 changes: 1 addition & 1 deletion src/fmpz_mat/test/t-minpoly.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ TEST_FUNCTION_START(fmpz_mat_minpoly, state)
fmpz_poly_init(r);

if (n_randint(state, 50) == 0)
fmpz_mat_randtest(A, state, 1000);
fmpz_mat_randtest(A, state, 10000);
else
fmpz_mat_randtest(A, state, 10);

Expand Down
Loading