Skip to content

Commit 27c25e9

Browse files
author
Jake Moss
committed
Add zero poly tests to other mpolys
1 parent 164d1d7 commit 27c25e9

File tree

3 files changed

+139
-11
lines changed

3 files changed

+139
-11
lines changed

src/fmpq_mpoly/test/t-compose_fmpq_mpoly.c

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ TEST_FUNCTION_START(fmpq_mpoly_compose_fmpq_mpoly, state)
1717
slong i, j, v;
1818

1919
{
20-
fmpq_mpoly_t A, A1, A2, B;
20+
slong nvarsAC = 2, nvarsB = 3;
21+
fmpq_mpoly_t A, A1, A2, B, B1;
2122
fmpq_mpoly_struct * Cp[3];
2223
fmpq_mpoly_struct C[3];
2324
fmpq_mpoly_ctx_t ctxAC, ctxB;
25+
slong * c;
2426

25-
fmpq_mpoly_ctx_init(ctxB, 3, ORD_LEX);
26-
fmpq_mpoly_ctx_init(ctxAC, 2, ORD_LEX);
27+
fmpq_mpoly_ctx_init(ctxB, nvarsB, ORD_LEX);
28+
fmpq_mpoly_ctx_init(ctxAC, nvarsAC, ORD_LEX);
2729

2830
fmpq_mpoly_init(B, ctxB);
2931
fmpq_mpoly_init(A, ctxAC);
@@ -70,11 +72,47 @@ TEST_FUNCTION_START(fmpq_mpoly_compose_fmpq_mpoly, state)
7072
fflush(stdout);
7173
flint_abort();
7274
}
75+
/* Aliased generator composition */
76+
c = (slong *) flint_malloc(nvarsB*sizeof(slong));
77+
fmpq_mpoly_init(B1, ctxB);
78+
fmpq_mpoly_set(B1, B, ctxB);
79+
for (i = 0; i < nvarsB; i++)
80+
c[i] = i;
81+
82+
fmpq_mpoly_compose_fmpq_mpoly_gen(B1, B1, c, ctxB, ctxB);
83+
if (!fmpq_mpoly_equal(B, B1, ctxB))
84+
TEST_FUNCTION_FAIL("Check composition with aliased generators\n");
85+
86+
/* Reverse the generators, twice */
87+
for (i = 0; i < nvarsB; i++)
88+
c[i] = nvarsB - i - 1;
89+
90+
fmpq_mpoly_compose_fmpq_mpoly_gen(B1, B1, c, ctxB, ctxB);
91+
if (fmpq_mpoly_equal(B, B1, ctxB))
92+
TEST_FUNCTION_FAIL("Check composition with reversed aliased generators\n");
93+
94+
fmpq_mpoly_compose_fmpq_mpoly_gen(B1, B1, c, ctxB, ctxB);
95+
if (!fmpq_mpoly_equal(B, B1, ctxB))
96+
TEST_FUNCTION_FAIL("Check composition with un-reversed aliased generators\n");
97+
98+
/* Composition with zero polys */
99+
fmpq_mpoly_zero(B1, ctxB);
100+
101+
fmpq_mpoly_compose_fmpq_mpoly_gen(A, B1, c, ctxB, ctxAC);
102+
if (!fmpq_mpoly_is_zero(B1, ctxB))
103+
TEST_FUNCTION_FAIL("Check composition with generators of zero poly\n");
104+
105+
fmpq_mpoly_set_str_pretty(C + 0, "2*x1", NULL, ctxAC);
106+
fmpq_mpoly_set_str_pretty(C + 1, "x2", NULL, ctxAC);
107+
fmpq_mpoly_set_str_pretty(C + 2, "1", NULL, ctxAC);
108+
if (!fmpq_mpoly_compose_fmpq_mpoly(A, B1, Cp, ctxB, ctxAC))
109+
TEST_FUNCTION_FAIL("Check example 4\n");
110+
111+
if (!fmpq_mpoly_is_zero(A, ctxAC))
112+
TEST_FUNCTION_FAIL("Check composition with zero poly\n");
73113

74114
fmpq_mpoly_clear(B, ctxB);
75115
fmpq_mpoly_clear(A, ctxAC);
76-
fmpq_mpoly_clear(A1, ctxAC);
77-
fmpq_mpoly_clear(A2, ctxAC);
78116
for (i = 0; i < 3; i++)
79117
fmpq_mpoly_clear(C + i, ctxAC);
80118

src/fmpz_mpoly/test/t-compose_fmpz_mpoly.c

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ TEST_FUNCTION_START(fmpz_mpoly_compose_fmpz_mpoly, state)
1717
slong i, j, v;
1818

1919
{
20-
fmpz_mpoly_t A, A1, A2, B;
20+
slong nvarsAC = 2, nvarsB = 3;
21+
fmpz_mpoly_t A, A1, A2, B, B1;
2122
fmpz_mpoly_struct * Cp[3];
2223
fmpz_mpoly_struct C[3];
2324
fmpz_mpoly_ctx_t ctxAC, ctxB;
25+
slong * c;
2426

25-
fmpz_mpoly_ctx_init(ctxB, 3, ORD_LEX);
26-
fmpz_mpoly_ctx_init(ctxAC, 2, ORD_LEX);
27+
fmpz_mpoly_ctx_init(ctxB, nvarsB, ORD_LEX);
28+
fmpz_mpoly_ctx_init(ctxAC, nvarsAC, ORD_LEX);
2729

2830
fmpz_mpoly_init(B, ctxB);
2931
fmpz_mpoly_init(A, ctxAC);
@@ -77,6 +79,49 @@ TEST_FUNCTION_START(fmpz_mpoly_compose_fmpz_mpoly, state)
7779
flint_abort();
7880
}
7981

82+
/* Aliased generator composition */
83+
c = (slong *) flint_malloc(nvarsB*sizeof(slong));
84+
fmpz_mpoly_init(B1, ctxB);
85+
fmpz_mpoly_set(B1, B, ctxB);
86+
for (i = 0; i < nvarsB; i++)
87+
c[i] = i;
88+
89+
fmpz_mpoly_compose_fmpz_mpoly_gen(B1, B1, c, ctxB, ctxB);
90+
if (!fmpz_mpoly_equal(B, B1, ctxB))
91+
TEST_FUNCTION_FAIL("Check composition with aliased generators\n");
92+
93+
/* Reverse the generators, twice */
94+
for (i = 0; i < nvarsB; i++)
95+
c[i] = nvarsB - i - 1;
96+
97+
fmpz_mpoly_compose_fmpz_mpoly_gen(B1, B1, c, ctxB, ctxB);
98+
if (fmpz_mpoly_equal(B, B1, ctxB))
99+
TEST_FUNCTION_FAIL("Check composition with reversed aliased generators\n");
100+
101+
fmpz_mpoly_compose_fmpz_mpoly_gen(B1, B1, c, ctxB, ctxB);
102+
if (!fmpz_mpoly_equal(B, B1, ctxB))
103+
TEST_FUNCTION_FAIL("Check composition with un-reversed aliased generators\n");
104+
105+
/* Composition with zero polys */
106+
fmpz_mpoly_zero(B1, ctxB);
107+
108+
fmpz_mpoly_compose_fmpz_mpoly_gen(A, B1, c, ctxB, ctxAC);
109+
if (!fmpz_mpoly_is_zero(B1, ctxB))
110+
TEST_FUNCTION_FAIL("Check composition with generators of zero poly\n");
111+
112+
fmpz_mpoly_set_str_pretty(C + 0, "2*x1", NULL, ctxAC);
113+
fmpz_mpoly_set_str_pretty(C + 1, "x2", NULL, ctxAC);
114+
fmpz_mpoly_set_str_pretty(C + 2, "1", NULL, ctxAC);
115+
if (!fmpz_mpoly_compose_fmpz_mpoly(A, B1, Cp, ctxB, ctxAC) ||
116+
!fmpz_mpoly_compose_fmpz_mpoly_horner(A1, B1, Cp, ctxB, ctxAC) ||
117+
!fmpz_mpoly_compose_fmpz_mpoly_geobucket(A2, B1, Cp, ctxB, ctxAC))
118+
TEST_FUNCTION_FAIL("Check example 4\n");
119+
120+
if (!fmpz_mpoly_is_zero(A, ctxAC) ||
121+
!fmpz_mpoly_is_zero(A1, ctxAC) ||
122+
!fmpz_mpoly_is_zero(A2, ctxAC))
123+
TEST_FUNCTION_FAIL("Check composition with zero poly\n");
124+
80125
fmpz_mpoly_clear(B, ctxB);
81126
fmpz_mpoly_clear(A, ctxAC);
82127
fmpz_mpoly_clear(A1, ctxAC);

src/nmod_mpoly/test/t-compose_nmod_mpoly.c

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ TEST_FUNCTION_START(nmod_mpoly_compose_nmod_mpoly, state)
1818
slong i, j, v;
1919

2020
{
21-
nmod_mpoly_t A, A1, A2, B;
21+
slong nvarsAC = 2, nvarsB = 3;
22+
nmod_mpoly_t A, A1, A2, B, B1;
2223
nmod_mpoly_struct * Cp[3];
2324
nmod_mpoly_struct C[3];
2425
nmod_mpoly_ctx_t ctxAC, ctxB;
26+
slong * c;
2527

26-
nmod_mpoly_ctx_init(ctxB, 3, ORD_LEX, 13);
27-
nmod_mpoly_ctx_init(ctxAC, 2, ORD_LEX, 13);
28+
nmod_mpoly_ctx_init(ctxB, nvarsB, ORD_LEX, 13);
29+
nmod_mpoly_ctx_init(ctxAC, nvarsAC, ORD_LEX, 13);
2830

2931
nmod_mpoly_init(B, ctxB);
3032
nmod_mpoly_init(A, ctxAC);
@@ -78,6 +80,49 @@ TEST_FUNCTION_START(nmod_mpoly_compose_nmod_mpoly, state)
7880
flint_abort();
7981
}
8082

83+
/* Aliased generator composition */
84+
c = (slong *) flint_malloc(nvarsB*sizeof(slong));
85+
nmod_mpoly_init(B1, ctxB);
86+
nmod_mpoly_set(B1, B, ctxB);
87+
for (i = 0; i < nvarsB; i++)
88+
c[i] = i;
89+
90+
nmod_mpoly_compose_nmod_mpoly_gen(B1, B1, c, ctxB, ctxB);
91+
if (!nmod_mpoly_equal(B, B1, ctxB))
92+
TEST_FUNCTION_FAIL("Check composition with aliased generators\n");
93+
94+
/* Reverse the generators, twice */
95+
for (i = 0; i < nvarsB; i++)
96+
c[i] = nvarsB - i - 1;
97+
98+
nmod_mpoly_compose_nmod_mpoly_gen(B1, B1, c, ctxB, ctxB);
99+
if (nmod_mpoly_equal(B, B1, ctxB))
100+
TEST_FUNCTION_FAIL("Check composition with reversed aliased generators\n");
101+
102+
nmod_mpoly_compose_nmod_mpoly_gen(B1, B1, c, ctxB, ctxB);
103+
if (!nmod_mpoly_equal(B, B1, ctxB))
104+
TEST_FUNCTION_FAIL("Check composition with un-reversed aliased generators\n");
105+
106+
/* Composition with zero polys */
107+
nmod_mpoly_zero(B1, ctxB);
108+
109+
nmod_mpoly_compose_nmod_mpoly_gen(A, B1, c, ctxB, ctxAC);
110+
if (!nmod_mpoly_is_zero(B1, ctxB))
111+
TEST_FUNCTION_FAIL("Check composition with generators of zero poly\n");
112+
113+
nmod_mpoly_set_str_pretty(C + 0, "2*x1", NULL, ctxAC);
114+
nmod_mpoly_set_str_pretty(C + 1, "x2", NULL, ctxAC);
115+
nmod_mpoly_set_str_pretty(C + 2, "1", NULL, ctxAC);
116+
if (!nmod_mpoly_compose_nmod_mpoly(A, B1, Cp, ctxB, ctxAC) ||
117+
!nmod_mpoly_compose_nmod_mpoly_horner(A1, B1, Cp, ctxB, ctxAC) ||
118+
!nmod_mpoly_compose_nmod_mpoly_geobucket(A2, B1, Cp, ctxB, ctxAC))
119+
TEST_FUNCTION_FAIL("Check example 4\n");
120+
121+
if (!nmod_mpoly_is_zero(A, ctxAC) ||
122+
!nmod_mpoly_is_zero(A1, ctxAC) ||
123+
!nmod_mpoly_is_zero(A2, ctxAC))
124+
TEST_FUNCTION_FAIL("Check composition with zero poly\n");
125+
81126
nmod_mpoly_clear(B, ctxB);
82127
nmod_mpoly_clear(A, ctxAC);
83128
nmod_mpoly_clear(A1, ctxAC);

0 commit comments

Comments
 (0)