File: fq_poly.c

package info (click to toggle)
flint 3.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 68,996 kB
  • sloc: ansic: 915,350; asm: 14,605; python: 5,340; sh: 4,512; lisp: 2,621; makefile: 787; cpp: 341
file content (165 lines) | stat: -rw-r--r-- 4,277 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
    Copyright (C) 2012 Sebastian Pancratz
    Copyright (C) 2013 Mike Hansen

    This file is part of FLINT.

    FLINT is free software: you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.  See <https://www.gnu.org/licenses/>.
*/

/*
    Demo FLINT program to demonstrate some use of the fq_poly module.
*/

#include <time.h>
#include <stdlib.h>
#include <flint/fmpz.h>
#include <flint/fq.h>
#include <flint/fq_poly.h>

int main(void)
{
    fmpz_t p;
    slong d, i;
    fq_ctx_t ctx;
    clock_t c0, c1;
    double c;
    fq_poly_t f, g, h;

    FLINT_TEST_INIT(state);

    printf("Polynomial multiplication over GF(q)\n");
    printf("------------------------------------\n");

    {
        printf("1)  Two length-10,000 polynomials over GF(3^2)\n");

        fmpz_init_set_ui(p, 3);
        d = 2;
        fq_ctx_init_conway(ctx, p, d, "X");

        fq_poly_init(f, ctx);
        fq_poly_init(g, ctx);
        fq_poly_init(h, ctx);

        fq_poly_randtest(g, state, 10000, ctx);
        fq_poly_randtest(h, state, 10000, ctx);

        c0 = clock();
        fq_poly_mul_classical(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("Classical: %fs\n", c);

        c0 = clock();
        for (i = 0; i < 100; i++)
            fq_poly_mul_reorder(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("Reorder: %fms\n", 10 * c);

        c0 = clock();
        for (i = 0; i < 100; i++)
            fq_poly_mul_KS(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("KS: %fms\n", 10 * c);

        fq_poly_clear(f, ctx);
        fq_poly_clear(g, ctx);
        fq_poly_clear(h, ctx);

        fq_ctx_clear(ctx);
        fmpz_clear(p);
    }
    {
        printf("2)  Two length-500 polynomials over GF(3^263)\n");

        fmpz_init_set_ui(p, 3);
        d = 263;
        fq_ctx_init_conway(ctx, p, d, "X");

        fq_poly_init(f, ctx);
        fq_poly_init(g, ctx);
        fq_poly_init(h, ctx);

        fq_poly_randtest(g, state, 500, ctx);
        fq_poly_randtest(h, state, 500, ctx);

        c0 = clock();
        fq_poly_mul_classical(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("Classical: %fs\n", c);

        c0 = clock();
        fq_poly_mul_reorder(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("Reorder: %fs\n", c);

        c0 = clock();
        for (i = 0; i < 100; i++)
            fq_poly_mul_KS(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("KS: %fms\n", 10 * c);

        fq_poly_clear(f, ctx);
        fq_poly_clear(g, ctx);
        fq_poly_clear(h, ctx);

        fq_ctx_clear(ctx);
        fmpz_clear(p);
    }
    {
        printf("3)  Two length-5 polynomials over GF(109987^4)\n");

        fmpz_init_set_ui(p, 109987);
        d = 4;
        fq_ctx_init_conway(ctx, p, d, "X");

        fq_poly_init(f, ctx);
        fq_poly_init(g, ctx);
        fq_poly_init(h, ctx);

        fq_poly_randtest(g, state, 4, ctx);
        fq_poly_randtest(h, state, 4, ctx);

        c0 = clock();
        for (i = 0; i < 1000 * 100; i++)
            fq_poly_mul_classical(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("Classical: %f\xb5s\n", 10 * c);

        c0 = clock();
        for (i = 0; i < 1000 * 100; i++)
            fq_poly_mul_reorder(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("Reorder: %f\xb5s\n", 10 * c);

        c0 = clock();
        for (i = 0; i < 1000 * 100; i++)
            fq_poly_mul_KS(f, g, h, ctx);
        c1 = clock();
        c  = (double) (c1 - c0) / CLOCKS_PER_SEC;
        printf("KS: %f\xb5s\n", 10 * c);

        fq_poly_clear(f, ctx);
        fq_poly_clear(g, ctx);
        fq_poly_clear(h, ctx);

        fq_ctx_clear(ctx);
        fmpz_clear(p);
    }

    FLINT_TEST_CLEAR(state);

    return 0;
}