1 /*
2     Copyright (C) 2009 William Hart
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
10 */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <gmp.h>
15 #include "flint.h"
16 #include "ulong_extras.h"
17 #include "fmpz.h"
18 
19 int
main(void)20 main(void)
21 {
22     int i, result;
23     FLINT_TEST_INIT(state);
24 
25     flint_printf("xgcd_partial....");
26     fflush(stdout);
27 
28 
29 
30     /* Test co2*r1 - co1*r2 = r2_orig */
31     for (i = 0; i < 1000 * flint_test_multiplier(); i++)
32     {
33         fmpz_t co1, co2, f, g, t1, t2, L;
34 
35         fmpz_init(co1);
36         fmpz_init(co2);
37         fmpz_init(f);
38         fmpz_init(g);
39         fmpz_init(L);
40         fmpz_init(t1);
41         fmpz_init(t2);
42 
43         fmpz_randtest_unsigned(g, state, 200);
44         fmpz_add_ui(g, g, 1);
45         fmpz_randm(f, state, g);
46         fmpz_randtest_unsigned(L, state, 200);
47 
48         fmpz_set(t2, g);
49         fmpz_abs(t2, t2);
50 
51         fmpz_xgcd_partial(co2, co1, g, f, L);
52 
53         fmpz_mul(t1, co2, f);
54         fmpz_submul(t1, co1, g);
55         fmpz_abs(t1, t1);
56 
57         result = fmpz_equal(t1, t2);
58         if (!result)
59         {
60             flint_printf("FAIL:\n\n");
61             flint_printf("co1 = "), fmpz_print(co1), flint_printf("\n");
62             flint_printf("co2 = "), fmpz_print(co2), flint_printf("\n");
63             flint_printf("f = "), fmpz_print(f), flint_printf("\n");
64             flint_printf("g = "), fmpz_print(g), flint_printf("\n");
65             flint_printf("L = "), fmpz_print(L), flint_printf("\n");
66             flint_printf("t1 = "), fmpz_print(t1), flint_printf("\n");
67             flint_printf("t2 = "), fmpz_print(t2), flint_printf("\n");
68             abort();
69         }
70 
71         fmpz_clear(co1);
72         fmpz_clear(co2);
73         fmpz_clear(f);
74         fmpz_clear(g);
75         fmpz_clear(L);
76         fmpz_clear(t1);
77         fmpz_clear(t2);
78     }
79 
80     FLINT_TEST_CLEANUP(state);
81 
82     flint_printf("PASS\n");
83     return 0;
84 }
85 
86