@@ -196,5 +196,65 @@ TEST_FUNCTION_START(fmpz_mpoly_inflate_deflate, state)
196196 fmpz_mpoly_ctx_clear (ctx );
197197 }
198198
199+ /* Check deflate with zero-stride does not divide by zero */
200+ for (i = 0 ; i < 40 * flint_test_multiplier (); i ++ )
201+ {
202+ fmpz_mpoly_ctx_t ctx ;
203+ fmpz_mpoly_t x , res ;
204+ fmpz * stride , * shift ;
205+
206+ fmpz_mpoly_ctx_init (ctx , 1 , ORD_LEX );
207+ fmpz_mpoly_init (x , ctx );
208+ fmpz_mpoly_init (res , ctx );
209+
210+ stride = flint_malloc (ctx -> minfo -> nvars * sizeof (fmpz ));
211+ shift = flint_malloc (ctx -> minfo -> nvars * sizeof (fmpz ));
212+ fmpz_init (stride + 0 );
213+ fmpz_init (shift + 0 );
214+
215+ /* Set x to just the generator */
216+ fmpz_mpoly_gen (x , 0 , ctx );
217+
218+ /* --- With zero shift --- */
219+ fmpz_set_ui (shift + 0 , 0 );
220+
221+ /* Attempt to deflate x to 1 with a shift and stride 0. */
222+ /* That is 1 -> (1 - 0) / 0 */
223+ /* Division by zero should not be raised here */
224+ fmpz_mpoly_deflate (res , x , shift , stride , ctx );
225+
226+ if (!fmpz_mpoly_equal_ui (res , 1 , ctx ))
227+ {
228+ printf ("FAIL\n" );
229+ flint_printf ("Check deflate with zero-shift and zero-stride\n" );
230+ fflush (stdout );
231+ flint_abort ();
232+ }
233+
234+ /* --- With non-zero shift --- */
235+ fmpz_set_ui (shift + 0 , 1 );
236+
237+ /* Attempt to deflate x to 1 with a shift of 1 and stride 0. */
238+ /* That is 1 -> (1 - 1) / 0 */
239+ /* Division by zero should not be raised here */
240+ fmpz_mpoly_deflate (res , x , shift , stride , ctx );
241+
242+ if (!fmpz_mpoly_equal_ui (res , 1 , ctx ))
243+ {
244+ printf ("FAIL\n" );
245+ flint_printf ("Check deflate with non-zero shift and zero-stride\n" );
246+ fflush (stdout );
247+ flint_abort ();
248+ }
249+
250+ fmpz_clear (stride + 0 );
251+ fmpz_clear (shift + 0 );
252+ flint_free (stride );
253+ flint_free (shift );
254+
255+ fmpz_mpoly_clear (x , ctx );
256+ fmpz_mpoly_ctx_clear (ctx );
257+ }
258+
199259 TEST_FUNCTION_END (state );
200260}
0 commit comments