diff --git a/fq_nmod_poly.h b/fq_nmod_poly.h index c7aef0defd..a70b2c9e89 100644 --- a/fq_nmod_poly.h +++ b/fq_nmod_poly.h @@ -39,6 +39,9 @@ #define FQ_NMOD_MULLOW_CLASSICAL_CUTOFF 6 #define FQ_NMOD_POLY_HGCD_CUTOFF 25 +#define FQ_NMOD_POLY_SMALL_GCD_CUTOFF 110 +#define FQ_NMOD_POLY_GCD_CUTOFF 120 + #ifdef T #undef T diff --git a/fq_nmod_poly/gcd.c b/fq_nmod_poly/gcd.c new file mode 100644 index 0000000000..a2095861d4 --- /dev/null +++ b/fq_nmod_poly/gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_nmod_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_nmod +#define CAP_T FQ_NMOD +#include "fq_poly_templates/gcd.c" +#undef CAP_T +#undef T diff --git a/fq_nmod_poly/gcd_hgcd.c b/fq_nmod_poly/gcd_hgcd.c new file mode 100644 index 0000000000..a24a73c688 --- /dev/null +++ b/fq_nmod_poly/gcd_hgcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_nmod_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_nmod +#define CAP_T FQ_NMOD +#include "fq_poly_templates/gcd_hgcd.c" +#undef CAP_T +#undef T diff --git a/fq_nmod_poly/profile/p-gcd.c b/fq_nmod_poly/profile/p-gcd.c new file mode 100644 index 0000000000..cd70226da7 --- /dev/null +++ b/fq_nmod_poly/profile/p-gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_nmod_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_nmod +#define CAP_T FQ_NMOD +#include "fq_poly_templates/profile/p-gcd.c" +#undef CAP_T +#undef T diff --git a/fq_nmod_poly/test/t-gcd.c b/fq_nmod_poly/test/t-gcd.c new file mode 100644 index 0000000000..b2e908af56 --- /dev/null +++ b/fq_nmod_poly/test/t-gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_nmod_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_nmod +#define CAP_T FQ_NMOD +#include "fq_poly_templates/test/t-gcd.c" +#undef CAP_T +#undef T diff --git a/fq_nmod_poly/test/t-gcd_hgcd.c b/fq_nmod_poly/test/t-gcd_hgcd.c new file mode 100644 index 0000000000..6dfa6b39da --- /dev/null +++ b/fq_nmod_poly/test/t-gcd_hgcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_nmod_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_nmod +#define CAP_T FQ_NMOD +#include "fq_poly_templates/test/t-gcd_hgcd.c" +#undef CAP_T +#undef T diff --git a/fq_poly.h b/fq_poly.h index 7380df9c64..9297f4c560 100644 --- a/fq_poly.h +++ b/fq_poly.h @@ -39,6 +39,8 @@ #define FQ_SQR_CLASSICAL_CUTOFF 6 #define FQ_POLY_HGCD_CUTOFF 30 +#define FQ_POLY_SMALL_GCD_CUTOFF 80 +#define FQ_POLY_GCD_CUTOFF 90 #ifdef T #undef T diff --git a/fq_poly/gcd.c b/fq_poly/gcd.c new file mode 100644 index 0000000000..b9b8d2fb40 --- /dev/null +++ b/fq_poly/gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq +#define CAP_T FQ +#include "fq_poly_templates/gcd.c" +#undef CAP_T +#undef T diff --git a/fq_poly/gcd_hgcd.c b/fq_poly/gcd_hgcd.c new file mode 100644 index 0000000000..6734bf134f --- /dev/null +++ b/fq_poly/gcd_hgcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq +#define CAP_T FQ +#include "fq_poly_templates/gcd_hgcd.c" +#undef CAP_T +#undef T diff --git a/fq_poly/profile/p-gcd.c b/fq_poly/profile/p-gcd.c new file mode 100644 index 0000000000..6eafdc2ae2 --- /dev/null +++ b/fq_poly/profile/p-gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq +#define CAP_T FQ +#include "fq_poly_templates/profile/p-gcd.c" +#undef CAP_T +#undef T diff --git a/fq_poly/test/t-gcd.c b/fq_poly/test/t-gcd.c new file mode 100644 index 0000000000..82e43adf13 --- /dev/null +++ b/fq_poly/test/t-gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq +#define CAP_T FQ +#include "fq_poly_templates/test/t-gcd.c" +#undef CAP_T +#undef T diff --git a/fq_poly/test/t-gcd_hgcd.c b/fq_poly/test/t-gcd_hgcd.c new file mode 100644 index 0000000000..e91b65b169 --- /dev/null +++ b/fq_poly/test/t-gcd_hgcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq +#define CAP_T FQ +#include "fq_poly_templates/test/t-gcd_hgcd.c" +#undef CAP_T +#undef T diff --git a/fq_poly_templates.h b/fq_poly_templates.h index 80d3b2cd92..d81d99964d 100644 --- a/fq_poly_templates.h +++ b/fq_poly_templates.h @@ -451,28 +451,31 @@ slong TEMPLATE(T, poly_hamming_weight)(const TEMPLATE(T, poly_t) op, const TEMPL /* Greatest common divisor *************************************************/ -void TEMPLATE(T, poly_gcd_euclidean)(TEMPLATE(T, poly_t) rop, const TEMPLATE(T, poly_t) op1, const TEMPLATE(T, poly_t) op2, - const TEMPLATE(T, ctx_t) ctx); - -slong _TEMPLATE(T, poly_gcd_euclidean)(TEMPLATE(T, struct)* G,const TEMPLATE(T, struct)* A, slong lenA, - const TEMPLATE(T, struct)* B, slong lenB, const TEMPLATE(T, t) invB, - const TEMPLATE(T, ctx_t) ctx); +void +TEMPLATE(T, poly_gcd_euclidean)(TEMPLATE(T, poly_t) rop, + const TEMPLATE(T, poly_t) op1, + const TEMPLATE(T, poly_t) op2, + const TEMPLATE(T, ctx_t) ctx); -static __inline__ -slong _TEMPLATE(T, poly_gcd)(TEMPLATE(T, struct)* G, const TEMPLATE(T, struct)* A, slong lenA, - const TEMPLATE(T, struct)* B, slong lenB, const TEMPLATE(T, t) invB, - const TEMPLATE(T, ctx_t) ctx) -{ - return _TEMPLATE(T, poly_gcd_euclidean)(G, A, lenA, B, lenB, invB, ctx); -} +slong +_TEMPLATE(T, poly_gcd_euclidean)(TEMPLATE(T, struct)* G, + const TEMPLATE(T, struct)* A, slong lenA, + const TEMPLATE(T, struct)* B, slong lenB, + const TEMPLATE(T, t) invB, + const TEMPLATE(T, ctx_t) ctx); -static __inline__ -void TEMPLATE(T, poly_gcd)(TEMPLATE(T, poly_t) rop, const TEMPLATE(T, poly_t) op1, const TEMPLATE(T, poly_t) op2, - const TEMPLATE(T, ctx_t) ctx) -{ - TEMPLATE(T, poly_gcd_euclidean)(rop,op1,op2,ctx); -} +slong +_TEMPLATE(T, poly_gcd)(TEMPLATE(T, struct)* G, + const TEMPLATE(T, struct)* A, slong lenA, + const TEMPLATE(T, struct)* B, slong lenB, + const TEMPLATE(T, t) invB, + const TEMPLATE(T, ctx_t) ctx); +void +TEMPLATE(T, poly_gcd)(TEMPLATE(T, poly_t) rop, + const TEMPLATE(T, poly_t) op1, + const TEMPLATE(T, poly_t) op2, + const TEMPLATE(T, ctx_t) ctx); slong _TEMPLATE(T, poly_hgcd)(TEMPLATE(T, struct) **M, slong *lenM, @@ -483,6 +486,18 @@ _TEMPLATE(T, poly_hgcd)(TEMPLATE(T, struct) **M, slong *lenM, const TEMPLATE(T, ctx_t) ctx); +slong +_TEMPLATE(T, poly_gcd_hgcd)(TEMPLATE(T, struct)* G, + const TEMPLATE(T, struct)* A, slong lenA, + const TEMPLATE(T, struct)* B, slong lenB, + const TEMPLATE(T, t) invB, + const TEMPLATE(T, ctx_t) ctx); + +void TEMPLATE(T, poly_gcd_hgcd)(TEMPLATE(T, poly_t) G, + const TEMPLATE(T, poly_t) A, + const TEMPLATE(T, poly_t) B, + const TEMPLATE(T, ctx_t) ctx); + /* Euclidean division ******************************************************/ ulong TEMPLATE(T, poly_remove)(TEMPLATE(T, poly_t) f, const TEMPLATE(T, poly_t) g, const TEMPLATE(T, ctx_t) ctx); diff --git a/fq_poly_templates/gcd.c b/fq_poly_templates/gcd.c new file mode 100644 index 0000000000..e16abeec0f --- /dev/null +++ b/fq_poly_templates/gcd.c @@ -0,0 +1,109 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + + +#ifdef T + +#include "templates.h" + +slong +_TEMPLATE(T, poly_gcd)(TEMPLATE(T, struct)* G, + const TEMPLATE(T, struct)* A, slong lenA, + const TEMPLATE(T, struct)* B, slong lenB, + const TEMPLATE(T, t) invB, + const TEMPLATE(T, ctx_t) ctx) +{ + slong cutoff; + if (fmpz_bits(TEMPLATE(T, ctx_prime)(ctx)) <= 8) + cutoff = TEMPLATE(CAP_T, POLY_SMALL_GCD_CUTOFF); + else + cutoff = TEMPLATE(CAP_T, POLY_GCD_CUTOFF); + + if (lenA < cutoff) + return _TEMPLATE(T, poly_gcd_euclidean)(G, A, lenA, B, lenB, invB, ctx); + else + return _TEMPLATE(T, poly_gcd_hgcd)(G, A, lenA, B, lenB, invB, ctx); +} + +void +TEMPLATE(T, poly_gcd)(TEMPLATE(T, poly_t) G, + const TEMPLATE(T, poly_t) A, + const TEMPLATE(T, poly_t) B, + const TEMPLATE(T, ctx_t) ctx) +{ + if (A->length < B->length) + { + TEMPLATE(T, poly_gcd)(G, B, A, ctx); + } + else /* lenA >= lenB >= 0 */ + { + slong lenA = A->length, lenB = B->length, lenG; + TEMPLATE(T, t) invB; + TEMPLATE(T, struct) *g; + + if (lenA == 0) /* lenA = lenB = 0 */ + { + TEMPLATE(T, poly_zero)(G, ctx); + } + else if (lenB == 0) /* lenA > lenB = 0 */ + { + TEMPLATE(T, poly_make_monic)(G, A, ctx); + } + else /* lenA >= lenB >= 1 */ + { + if (G == A || G == B) + { + g = _TEMPLATE(T, vec_init)(FLINT_MIN(lenA, lenB), ctx); + } + else + { + TEMPLATE(T, poly_fit_length)(G, FLINT_MIN(lenA, lenB), ctx); + g = G->coeffs; + } + + TEMPLATE(T, init)(invB, ctx); + TEMPLATE(T, inv)(invB, TEMPLATE(T, poly_lead)(B, ctx), ctx); + lenG = _TEMPLATE(T, poly_gcd)(g, A->coeffs, lenA, + B->coeffs, lenB, invB, ctx); + TEMPLATE(T, clear)(invB, ctx); + + if (G == A || G == B) + { + _TEMPLATE(T, vec_clear)(G->coeffs, G->alloc, ctx); + G->coeffs = g; + G->alloc = FLINT_MIN(lenA, lenB); + G->length = FLINT_MIN(lenA, lenB); + } + _TEMPLATE(T, poly_set_length)(G, lenG, ctx); + + if (G->length == 1) + TEMPLATE(T, one)(G->coeffs, ctx); + else + TEMPLATE(T, poly_make_monic)(G, G, ctx); + } + } +} + +#endif diff --git a/fq_poly_templates/gcd_hgcd.c b/fq_poly_templates/gcd_hgcd.c new file mode 100644 index 0000000000..3aa682c7f8 --- /dev/null +++ b/fq_poly_templates/gcd_hgcd.c @@ -0,0 +1,177 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + + +#ifdef T + +#include "templates.h" + +#include +#include "mpn_extras.h" + +#define __set(B, lenB, A, lenA) \ +do { \ + _TEMPLATE(T, vec_set)((B), (A), (lenA), ctx); \ + (lenB) = (lenA); \ +} while (0) + +#define __rem(R, lenR, A, lenA, B, lenB, invB) \ +do { \ + if ((lenA) >= (lenB)) \ + { \ + _TEMPLATE(T, poly_rem)((R), (A), (lenA), (B), (lenB), (invB), ctx); \ + (lenR) = (lenB) - 1; \ + TEMPLATE(CAP_T, VEC_NORM)(R, lenR, ctx); \ + } \ + else \ + { \ + _TEMPLATE(T, vec_set)((R), (A), (lenA), ctx); \ + (lenR) = (lenA); \ + } \ +} while (0) + +/* + XXX: Incidentally, this implementation currently supports aliasing. + But since this may change in the future, no function other than + TEMPLATE(T, poly_gcd_hgcd)() should rely on this. + */ + +slong +_TEMPLATE(T, poly_gcd_hgcd)(TEMPLATE(T, struct)* G, + const TEMPLATE(T, struct)* A, slong lenA, + const TEMPLATE(T, struct)* B, slong lenB, + const TEMPLATE(T, t) invB, + const TEMPLATE(T, ctx_t) ctx) +{ + slong cutoff, lenG, lenJ, lenR; + TEMPLATE(T, struct)* J = _TEMPLATE(T, vec_init)(2 * lenB, ctx); + TEMPLATE(T, struct)* R = J + lenB; + TEMPLATE(T, t) inv; + + if (fmpz_bits(TEMPLATE(T, ctx_prime)(ctx)) <= 8) + cutoff = TEMPLATE(CAP_T, POLY_SMALL_GCD_CUTOFF); + else + cutoff = TEMPLATE(CAP_T, POLY_GCD_CUTOFF); + + __rem(R, lenR, A, lenA, B, lenB, invB); + + if (lenR == 0) + { + __set(G, lenG, B, lenB); + } + else + { + TEMPLATE(T, init)(inv, ctx); + + _TEMPLATE(T, poly_hgcd)(NULL, NULL, G, &(lenG), J, &(lenJ), B, lenB, R, lenR, ctx); + + while (lenJ != 0) + { + TEMPLATE(T, inv)(inv, J + lenJ - 1, ctx); + __rem(R, lenR, G, lenG, J, lenJ, inv); + + if (lenR == 0) + { + __set(G, lenG, J, lenJ); + break; + } + if (lenJ < cutoff) + { + TEMPLATE(T, inv)(inv, R + lenR - 1, ctx); + lenG = _TEMPLATE(T, poly_gcd_euclidean)(G, J, lenJ, R, lenR, inv, ctx); + break; + } + + _TEMPLATE(T, poly_hgcd)(NULL, NULL, G, &(lenG), J, &(lenJ), J, lenJ, R, lenR, ctx); + } + TEMPLATE(T, clear)(inv, ctx); + } + _TEMPLATE(T, vec_clear)(J, 2 * lenB, ctx); + + return lenG; +} + +void TEMPLATE(T, poly_gcd_hgcd)(TEMPLATE(T, poly_t) G, + const TEMPLATE(T, poly_t) A, + const TEMPLATE(T, poly_t) B, + const TEMPLATE(T, ctx_t) ctx) +{ + if (A->length < B->length) + { + TEMPLATE(T, poly_gcd_hgcd)(G, B, A, ctx); + } + else /* lenA >= lenB >= 0 */ + { + slong lenA = A->length, lenB = B->length, lenG; + TEMPLATE(T, poly_t) tG; + TEMPLATE(T, t) invB; + TEMPLATE(T, struct)* g; + + if (lenA == 0) /* lenA = lenB = 0 */ + { + TEMPLATE(T, poly_zero)(G, ctx); + } + else if (lenB == 0) /* lenA > lenB = 0 */ + { + TEMPLATE(T, poly_make_monic)(G, A, ctx); + } + else /* lenA >= lenB >= 1 */ + { + if (G == A || G == B) + { + TEMPLATE(T, poly_init2)(tG, FLINT_MIN(lenA, lenB), ctx); + g = tG->coeffs; + } + else + { + TEMPLATE(T, poly_fit_length)(G, FLINT_MIN(lenA, lenB), ctx); + g = G->coeffs; + } + + TEMPLATE(T, init)(invB, ctx); + TEMPLATE(T, inv)(invB, B->coeffs + lenB - 1, ctx); + + lenG = _TEMPLATE(T, poly_gcd_hgcd)(g, A->coeffs, lenA, + B->coeffs, lenB, invB, ctx); + + if (G == A || G == B) + { + TEMPLATE(T, poly_swap)(tG, G, ctx); + TEMPLATE(T, poly_clear)(tG, ctx); + } + G->length = lenG; + + if (G->length == 1) + TEMPLATE(T, one)(G->coeffs, ctx); + else + TEMPLATE(T, poly_make_monic)(G, G, ctx); + } + } +} + +#undef __set +#undef __rem + +#endif diff --git a/fq_poly_templates/profile/p-gcd-old.c b/fq_poly_templates/profile/p-gcd-old.c new file mode 100644 index 0000000000..ef1da7b1be --- /dev/null +++ b/fq_poly_templates/profile/p-gcd-old.c @@ -0,0 +1,165 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + + +#ifdef T + +#include "templates.h" + +#include +#include +#include +#include "profiler.h" + +/* + Profiling and benchmarking code for GCD in fq_poly_templates. + + For three different prime moduli p[i], for a sequence of degrees degs[k], + we create 100 random polynomials A, B, C of degree degs[k]/2 and then + compute GCD(AC, BC) repeatedly, runs[i][k] times. + */ + +#define N 50 + +int main(int argc, char** argv) +{ + FLINT_TEST_INIT(state); + + fmpz_t pp; + slong ext = atoi(argv[1]); + + mp_limb_t p[] = {17ul, 2147483659ul, 9223372036854775837ul}; + const slong degs[] = { 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, + 220, 240, 260, 280, 300, 320, 340, 360, 380, 400, + 420, 440, 460, 480, 500, 520, 540, 560, 580, 600, + 620, 640, 660, 680, 700, 720, 740, 760, 780, 800, + 820, 840, 860, 880, 900, 920, 940, 960, 980, 1000}; + const slong runs[3][N] = {{ 2000, 1000, 500, 300, 200, 200, 200, 180, 140, 140, + 100, 80, 80, 80, 50, 50, 40, 30, 30, 20, + 18, 16, 14, 12, 10, 10, 10, 10, 10, 10, + 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, + 7, 7, 6, 6, 6, 6, 5, 5, 5, 5}, + { 1400, 800, 400, 260, 160, 140, 120, 100, 60, 60, + 50, 50, 40, 40, 30, 30, 20, 20, 20, 15, + 14, 13, 12, 11, 10, 10, 10, 10, 10, 10, + 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, + 6, 6, 6, 5, 5, 5, 5, 5, 4, 4}, + { 1400, 800, 400, 260, 160, 120, 100, 80, 60, 50, + 50, 40, 30, 20, 20, 20, 15, 15, 15, 12, + 12, 11, 11, 10, 10, 10, 10, 10, 10, 10, + 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, + 6, 6, 6, 5, 5, 5, 5, 5, 4, 4}}; + + long double cpu[3][2][N]; + slong i, k, c, n; + + TEMPLATE(T, ctx_t) ctx; + TEMPLATE(T, poly_t) A, B, C, G; + + fmpz_init(pp); + + for (i = 0; i < 3; i++) + { + flint_printf("---[Modulus %wu^%wd]---\n", p[i], ext), fflush(stdout); + fmpz_set_ui(pp, p[i]); + TEMPLATE(T, ctx_init)(ctx, pp, ext, "a"); + + for (k = 0; k < N; k++) + { + const slong d = degs[k]; + slong r = runs[i][k]; + /*r = 5;*/ + + cpu[i][0][k] = (long double) 0.0; + cpu[i][1][k] = (long double) 0.0; + + TEMPLATE(T, poly_init)(A, ctx); + TEMPLATE(T, poly_init)(B, ctx); + TEMPLATE(T, poly_init)(C, ctx); + TEMPLATE(T, poly_init)(G, ctx); + + for (c = 0; c < 100; c++) + { + TEMPLATE(T, poly_randtest)(A, state, d/2, ctx); + TEMPLATE(T, poly_randtest)(B, state, d/2, ctx); + TEMPLATE(T, poly_randtest)(C, state, d/2, ctx); + TEMPLATE(T, poly_mul)(A, A, C, ctx); + TEMPLATE(T, poly_mul)(B, B, C, ctx); + flint_printf("%4ld %10.8lf %10.8lf\n", A->length, cpu[i][0][k], cpu[i][1][k]); + + init_clock(0); + prof_start(); + for (n = 0; n < r; n++) + TEMPLATE(T, poly_gcd_euclidean)(G, A, B, ctx); + prof_stop(); + cpu[i][1][k] += get_clock(0); + + init_clock(0); + prof_start(); + for (n = 0; n < r; n++) + TEMPLATE(T, poly_gcd_hgcd)(G, A, B, ctx); + prof_stop(); + cpu[i][1][k] += get_clock(0); + } + + cpu[i][0][k] = (long double) cpu[i][0][k] / (long double) CLOCKS_PER_SEC; + cpu[i][1][k] = (long double) cpu[i][1][k] / (long double) CLOCKS_PER_SEC; + + cpu[i][0][k] = (long double) cpu[i][0][k] / (long double) (100*r); + cpu[i][1][k] = (long double) cpu[i][1][k] / (long double) (100*r); + + flint_printf("%4ld %10.8llf %10.8llf\n", A->length, cpu[i][0][k], cpu[i][1][k]); + fflush(stdout); + + TEMPLATE(T, poly_clear)(A, ctx); + TEMPLATE(T, poly_clear)(B, ctx); + TEMPLATE(T, poly_clear)(C, ctx); + TEMPLATE(T, poly_clear)(G, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + } + + flint_printf("cpu = ["); + for (i = 0; i < 3; i++) + { + flint_printf("[["); + for (k = 0; k < N; k++) + flint_printf("%.WORD(8)f,", cpu[i][0][k]); + flint_printf("],"); + flint_printf("["); + for (k = 0; k < N; k++) + flint_printf("%.WORD(8)f,", cpu[i][1][k]); + flint_printf("]],"); + } + flint_printf("]\n"); + + flint_randclear(state); + return EXIT_SUCCESS; +} + + + +#endif diff --git a/fq_poly_templates/profile/p-gcd.c b/fq_poly_templates/profile/p-gcd.c new file mode 100644 index 0000000000..f85f9b584d --- /dev/null +++ b/fq_poly_templates/profile/p-gcd.c @@ -0,0 +1,142 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#ifdef T + +#include "flint.h" +#include "templates.h" + +#include +#include "profiler.h" + +#define nalgs 2 +#define cpumin 2 +#define ncases 50 + +int +main(int argc, char** argv) +{ + fmpz_t p, q; + int l, n, reps = 0; + slong d, len; + TEMPLATE(T, ctx_t) ctx; + TEMPLATE(T, poly_t) a, b, c, g; + slong i; + double beta; + + double s[nalgs]; + + FLINT_TEST_INIT(state); + + fmpz_init(p); + fmpz_set_str(p, argv[1], 10); + d = atol(argv[2]); + len = atol(argv[3]); + + TEMPLATE(T, ctx_init)(ctx, p, d, "a"); + + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(c, ctx); + TEMPLATE(T, poly_init)(g, ctx); + + fmpz_init(q); + TEMPLATE(T, ctx_order)(q, ctx); + + for (l = 0; l < nalgs; l++) + s[l] = 0.0; + + for (n = 0; n < ncases; n++) + { + double t[nalgs]; + int lo, loops = 1; + + /* + Construct random elements of fq + */ + { + TEMPLATE(T, poly_randtest_monic)(a, state, len / 2, ctx); + TEMPLATE(T, poly_randtest_monic)(b, state, len / 2, ctx); + TEMPLATE(T, poly_randtest_monic)(c, state, len / 2, ctx); + TEMPLATE(T, poly_mul)(a, a, c, ctx); + TEMPLATE(T, poly_mul)(b, b, c, ctx); + } + + loop: + + t[0] = 0.0; + init_clock(0); + prof_start(); + for (lo = 0; lo < loops; lo++) + { + TEMPLATE(T, poly_gcd_euclidean)(g, a, b, ctx); + } + prof_stop(); + t[0] += get_clock(0); + + + t[1] = 0.0; + init_clock(0); + prof_start(); + for (lo = 0; lo < loops; lo++) + { + TEMPLATE(T, poly_gcd_hgcd)(g, a, b, ctx); + } + prof_stop(); + t[1] += get_clock(0); + + for (l = 0; l < nalgs; l++) + if (t[l] * FLINT_CLOCK_SCALE_FACTOR <= cpumin) + { + loops *= 10; + goto loop; + } + + for (l = 0; l < nalgs; l++) + s[l] += t[l]; + reps += loops; + } + + for (l = 0; l < nalgs; l++) + { + printf("%20f", s[l] / (double) reps); + fflush(stdout); + } + printf("\n"); + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(c, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + TEMPLATE(T, ctx_clear)(ctx); + fmpz_clear(p); + fmpz_clear(q); + + FLINT_TEST_CLEANUP(state); + + return 0; +} + +#endif diff --git a/fq_poly_templates/test/t-gcd.c b/fq_poly_templates/test/t-gcd.c new file mode 100644 index 0000000000..a44ea2fec6 --- /dev/null +++ b/fq_poly_templates/test/t-gcd.c @@ -0,0 +1,231 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + + +#ifdef T + +#include "templates.h" + +#include +#include + + +int +main(void) +{ + int i, result; + FLINT_TEST_INIT(state); + + flint_printf("gcd...."); + fflush(stdout); + + /* Check that gcd(a,a) = a (made monic) */ + + for (i = 0; i < 100 * flint_test_multiplier(); i++) + { + slong len; + TEMPLATE(T, ctx_t) ctx; + + TEMPLATE(T, poly_t) a,b,g; + + len = n_randint(state, 15) + 1; + TEMPLATE(T, ctx_randtest)(ctx, state); + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(g, ctx); + + + TEMPLATE(T, poly_randtest_not_zero)(a, state, len, ctx); + TEMPLATE(T, poly_make_monic)(b,a,ctx); + TEMPLATE(T, poly_gcd)(g,a,a,ctx); + + result = (TEMPLATE(T, poly_equal)(g, b, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + flint_printf("a = "), TEMPLATE(T, poly_print_pretty)(a, "X", ctx), flint_printf("\n"); + flint_printf("b = "), TEMPLATE(T, poly_print_pretty)(b, "X", ctx), flint_printf("\n"); + flint_printf("g = "), TEMPLATE(T, poly_print_pretty)(g, "X", ctx), flint_printf("\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + } + + + /* + Find coprime polys, multiply by another poly + and check the GCD is that poly + */ + for (i = 0; i < 10 * flint_test_multiplier(); i++) + { + slong len,j; + TEMPLATE(T, ctx_t) ctx; + + TEMPLATE(T, poly_t) a,b,c,g; + + len = n_randint(state, 15) + 1; + TEMPLATE(T, ctx_randtest)(ctx, state); + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(c, ctx); + TEMPLATE(T, poly_init)(g, ctx); + + + TEMPLATE(T, poly_randtest_not_zero)(a, state, len, ctx); + + + for(j=0;(j<100* flint_test_multiplier()) && !TEMPLATE(T, poly_is_one)(g, ctx);j++){ + TEMPLATE(T, poly_randtest_not_zero)(b, state, len, ctx); + TEMPLATE(T, poly_gcd)(g,a,b,ctx); + + + } + + if(!TEMPLATE(T, poly_is_one)(g, ctx)){ + flint_printf("FAIL:\n"); + flint_printf("could not find coprime polynomials after %wd tries\n",j+1); + abort(); + } + + for(j=0;(j<100* flint_test_multiplier()) && (c->length<2);j++) + TEMPLATE(T, poly_randtest_not_zero)(c, state, len+2, ctx); + + if(c->length<2){ + flint_printf("FAIL:\n"); + flint_printf("could not find non-unit polynomial after %wd tries\n",j+1); + abort(); + } + + TEMPLATE(T, poly_make_monic)(c, c,ctx); + + TEMPLATE(T, poly_mul)(a, a, c,ctx); + TEMPLATE(T, poly_mul)(b, b, c,ctx); + + TEMPLATE(T, poly_gcd)(g, a, b,ctx); + + result = (TEMPLATE(T, poly_equal)(g, c, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + flint_printf("a = "), TEMPLATE(T, poly_print_pretty)(a, "X", ctx), flint_printf("\n"); + flint_printf("b = "), TEMPLATE(T, poly_print_pretty)(b, "X", ctx), flint_printf("\n"); + flint_printf("c = "), TEMPLATE(T, poly_print_pretty)(c, "X", ctx), flint_printf("\n"); + flint_printf("g = "), TEMPLATE(T, poly_print_pretty)(g, "X", ctx), flint_printf("\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(c, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + + /* Check aliasing of a and g */ + for (i = 0; i < 10 * flint_test_multiplier(); i++) + { + slong len; + TEMPLATE(T, ctx_t) ctx; + + TEMPLATE(T, poly_t) a,b,g; + + len = n_randint(state, 200) + 1; + TEMPLATE(T, ctx_randtest)(ctx, state); + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(g, ctx); + + TEMPLATE(T, poly_randtest_not_zero)(a, state, len, ctx); + TEMPLATE(T, poly_randtest_not_zero)(b, state, len, ctx); + + TEMPLATE(T, poly_gcd)(g, a, b,ctx); + TEMPLATE(T, poly_gcd)(a, a, b,ctx); + + result = (TEMPLATE(T, poly_equal)(g, a, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + flint_printf("a = "), TEMPLATE(T, poly_print_pretty)(a, "X", ctx), flint_printf("\n"); + flint_printf("b = "), TEMPLATE(T, poly_print_pretty)(b, "X", ctx), flint_printf("\n"); + flint_printf("g = "), TEMPLATE(T, poly_print_pretty)(g, "X", ctx), flint_printf("\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + + + /* Check aliasing of b and g */ + for (i = 0; i < 10 * flint_test_multiplier(); i++) + { + slong len; + TEMPLATE(T, ctx_t) ctx; + + TEMPLATE(T, poly_t) a,b,g; + + len = n_randint(state, 200) + 1; + TEMPLATE(T, ctx_randtest)(ctx, state); + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(g, ctx); + + TEMPLATE(T, poly_randtest_not_zero)(a, state, len, ctx); + TEMPLATE(T, poly_randtest_not_zero)(b, state, len, ctx); + + TEMPLATE(T, poly_gcd)(g, a, b,ctx); + TEMPLATE(T, poly_gcd)(b, a, b,ctx); + + result = (TEMPLATE(T, poly_equal)(g, b, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + flint_printf("a = "), TEMPLATE(T, poly_print_pretty)(a, "X", ctx), flint_printf("\n"); + flint_printf("b = "), TEMPLATE(T, poly_print_pretty)(b, "X", ctx), flint_printf("\n"); + flint_printf("g = "), TEMPLATE(T, poly_print_pretty)(g, "X", ctx), flint_printf("\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + + FLINT_TEST_CLEANUP(state); + flint_printf("PASS\n"); + return 0; +} + + +#endif diff --git a/fq_poly_templates/test/t-gcd_hgcd.c b/fq_poly_templates/test/t-gcd_hgcd.c new file mode 100644 index 0000000000..3564cb9f74 --- /dev/null +++ b/fq_poly_templates/test/t-gcd_hgcd.c @@ -0,0 +1,168 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + + +#ifdef T + +#include "templates.h" + +int +main(void) +{ + int i, result; + FLINT_TEST_INIT(state); + + + flint_printf("gcd_hgcd...."); + fflush(stdout); + + /* + Find coprime polys, multiply by another poly + and check the GCD is that poly + */ + for (i = 0; i < 10 * flint_test_multiplier(); i++) + { + TEMPLATE(T, poly_t) a, b, c, g; + TEMPLATE(T, ctx_t) ctx; + + TEMPLATE(T, ctx_randtest)(ctx, state); + + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(c, ctx); + TEMPLATE(T, poly_init)(g, ctx); + + do { + TEMPLATE(T, poly_randtest)(a, state, n_randint(state, 300), ctx); + TEMPLATE(T, poly_randtest)(b, state, n_randint(state, 300), ctx); + TEMPLATE(T, poly_gcd_hgcd)(g, a, b, ctx); + } while (g->length != 1); + + do { + TEMPLATE(T, poly_randtest)(c, state, n_randint(state, 300), ctx); + } while (c->length < 2); + TEMPLATE(T, poly_make_monic)(c, c, ctx); + + TEMPLATE(T, poly_mul)(a, a, c, ctx); + TEMPLATE(T, poly_mul)(b, b, c, ctx); + + TEMPLATE(T, poly_gcd_hgcd)(g, a, b, ctx); + + result = (TEMPLATE(T, poly_equal)(g, c, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + TEMPLATE(T, poly_print_pretty)(a, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(b, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(c, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(g, "x", ctx), flint_printf("\n\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(c, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + + /* Check aliasing of a and g */ + for (i = 0; i < 10 * flint_test_multiplier(); i++) + { + TEMPLATE(T, ctx_t) ctx; + TEMPLATE(T, poly_t) a, b, g; + + TEMPLATE(T, ctx_randtest)(ctx, state); + + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(g, ctx); + TEMPLATE(T, poly_randtest)(a, state, n_randint(state, 300), ctx); + TEMPLATE(T, poly_randtest)(b, state, n_randint(state, 300), ctx); + + TEMPLATE(T, poly_gcd_hgcd)(g, a, b, ctx); + TEMPLATE(T, poly_gcd_hgcd)(a, a, b, ctx); + + result = (TEMPLATE(T, poly_equal)(a, g, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + TEMPLATE(T, poly_print_pretty)(a, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(b, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(g, "x", ctx), flint_printf("\n\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + + /* Check aliasing of b and g */ + for (i = 0; i < 10 * flint_test_multiplier(); i++) + { + TEMPLATE(T, ctx_t) ctx; + TEMPLATE(T, poly_t) a, b, g; + + TEMPLATE(T, ctx_randtest)(ctx, state); + + TEMPLATE(T, poly_init)(a, ctx); + TEMPLATE(T, poly_init)(b, ctx); + TEMPLATE(T, poly_init)(g, ctx); + TEMPLATE(T, poly_randtest)(a, state, n_randint(state, 300), ctx); + TEMPLATE(T, poly_randtest)(b, state, n_randint(state, 300), ctx); + + TEMPLATE(T, poly_gcd_hgcd)(g, a, b, ctx); + TEMPLATE(T, poly_gcd_hgcd)(b, a, b, ctx); + + result = (TEMPLATE(T, poly_equal)(b, g, ctx)); + if (!result) + { + flint_printf("FAIL:\n"); + TEMPLATE(T, poly_print_pretty)(a, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(b, "x", ctx), flint_printf("\n\n"); + TEMPLATE(T, poly_print_pretty)(g, "x", ctx), flint_printf("\n\n"); + abort(); + } + + TEMPLATE(T, poly_clear)(a, ctx); + TEMPLATE(T, poly_clear)(b, ctx); + TEMPLATE(T, poly_clear)(g, ctx); + + TEMPLATE(T, ctx_clear)(ctx); + } + + FLINT_TEST_CLEANUP(state); + + flint_printf("PASS\n"); + return 0; +} + + + +#endif diff --git a/fq_zech_poly.h b/fq_zech_poly.h index d28d7bf621..95bc7962ba 100644 --- a/fq_zech_poly.h +++ b/fq_zech_poly.h @@ -37,6 +37,8 @@ #define FQ_ZECH_MULLOW_CLASSICAL_CUTOFF 90 #define FQ_ZECH_POLY_HGCD_CUTOFF 35 +#define FQ_ZECH_POLY_GCD_CUTOFF 96 +#define FQ_ZECH_POLY_SMALL_GCD_CUTOFF 96 #ifdef T #undef T diff --git a/fq_zech_poly/gcd.c b/fq_zech_poly/gcd.c new file mode 100644 index 0000000000..983b189577 --- /dev/null +++ b/fq_zech_poly/gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_zech_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_zech +#define CAP_T FQ_ZECH +#include "fq_poly_templates/gcd.c" +#undef CAP_T +#undef T diff --git a/fq_zech_poly/gcd_hgcd.c b/fq_zech_poly/gcd_hgcd.c new file mode 100644 index 0000000000..87f5481153 --- /dev/null +++ b/fq_zech_poly/gcd_hgcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_zech_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_zech +#define CAP_T FQ_ZECH +#include "fq_poly_templates/gcd_hgcd.c" +#undef CAP_T +#undef T diff --git a/fq_zech_poly/profile/p-gcd.c b/fq_zech_poly/profile/p-gcd.c new file mode 100644 index 0000000000..06e02fe944 --- /dev/null +++ b/fq_zech_poly/profile/p-gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_zech_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_zech +#define CAP_T FQ_ZECH +#include "fq_poly_templates/profile/p-gcd.c" +#undef CAP_T +#undef T diff --git a/fq_zech_poly/test/t-gcd.c b/fq_zech_poly/test/t-gcd.c new file mode 100644 index 0000000000..aba0846f54 --- /dev/null +++ b/fq_zech_poly/test/t-gcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_zech_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_zech +#define CAP_T FQ_ZECH +#include "fq_poly_templates/test/t-gcd.c" +#undef CAP_T +#undef T diff --git a/fq_zech_poly/test/t-gcd_hgcd.c b/fq_zech_poly/test/t-gcd_hgcd.c new file mode 100644 index 0000000000..3a8230458a --- /dev/null +++ b/fq_zech_poly/test/t-gcd_hgcd.c @@ -0,0 +1,36 @@ +/*============================================================================= + + This file is part of FLINT. + + FLINT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + FLINT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FLINT; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +=============================================================================*/ +/****************************************************************************** + + Copyright (C) 2013 Mike Hansen + +******************************************************************************/ + +#include "fq_zech_poly.h" + +#ifdef T +#undef T +#endif + +#define T fq_zech +#define CAP_T FQ_ZECH +#include "fq_poly_templates/test/t-gcd_hgcd.c" +#undef CAP_T +#undef T