ALL: Add flint
This commit is contained in:
78
external/flint-2.4.3/examples/crt.c
vendored
Normal file
78
external/flint-2.4.3/examples/crt.c
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for incremental multimodular reduction and
|
||||
reconstruction using the Chinese Remainder Theorem.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
slong i, bit_bound;
|
||||
mp_limb_t prime, res;
|
||||
fmpz_t x, y, prod;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
flint_printf("Syntax: crt <integer>\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fmpz_init(x);
|
||||
fmpz_init(y);
|
||||
fmpz_init(prod);
|
||||
|
||||
fmpz_set_str(x, argv[1], 10);
|
||||
bit_bound = fmpz_bits(x) + 2;
|
||||
|
||||
fmpz_zero(y);
|
||||
fmpz_one(prod);
|
||||
|
||||
prime = 0;
|
||||
for (i = 0; fmpz_bits(prod) < bit_bound; i++)
|
||||
{
|
||||
prime = n_nextprime(prime, 0);
|
||||
res = fmpz_fdiv_ui(x, prime);
|
||||
fmpz_CRT_ui(y, y, prod, res, prime, 1);
|
||||
|
||||
flint_printf("residue mod %wu = %wu; reconstruction = ", prime, res);
|
||||
fmpz_print(y);
|
||||
flint_printf("\n");
|
||||
|
||||
fmpz_mul_ui(prod, prod, prime);
|
||||
}
|
||||
|
||||
fmpz_clear(x);
|
||||
fmpz_clear(y);
|
||||
fmpz_clear(prod);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
68
external/flint-2.4.3/examples/crt.cpp
vendored
Normal file
68
external/flint-2.4.3/examples/crt.cpp
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Fredrik Johansson
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for incremental multimodular reduction and
|
||||
reconstruction using the Chinese Remainder Theorem.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "fmpzxx.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
using namespace flint;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
flint_printf("Syntax: crt <integer>\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fmpzxx x(argv[1]);
|
||||
slong bit_bound = bits(x) + 2;
|
||||
|
||||
fmpzxx y(0);
|
||||
fmpzxx prod(1);
|
||||
|
||||
mp_limb_t prime = 0;
|
||||
for (unsigned i = 0; bits(prod) < bit_bound; i++)
|
||||
{
|
||||
prime = n_nextprime(prime, 0);
|
||||
|
||||
ulong res = (x % prime).to<ulong>();
|
||||
y = y.CRT(prod, res, prime, true);
|
||||
|
||||
std::cout << "residue mod " << prime << " = " << res;
|
||||
std::cout << "; reconstruction = " << y << '\n';
|
||||
|
||||
prod *= prime;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
69
external/flint-2.4.3/examples/delta_qexp.c
vendored
Normal file
69
external/flint-2.4.3/examples/delta_qexp.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2007 David Harvey, William Hart
|
||||
Copyright (C) 2010 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for computing the q-expansion of the delta function.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "arith.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
fmpz_t c, n;
|
||||
slong N = 0;
|
||||
|
||||
if (argc == 2)
|
||||
N = atol(argv[1]);
|
||||
|
||||
if (argc != 2 || N < 1)
|
||||
{
|
||||
flint_printf("Syntax: delta_qexp <integer>\n");
|
||||
flint_printf("where <integer> is the (positive) number of terms to compute\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fmpz_init(c);
|
||||
fmpz_init(n);
|
||||
|
||||
fmpz_set_si(n, N);
|
||||
arith_ramanujan_tau(c, n);
|
||||
|
||||
flint_printf("Coefficient of q^%wd is ", N);
|
||||
fmpz_print(c);
|
||||
flint_printf("\n");
|
||||
|
||||
fmpz_clear(c);
|
||||
fmpz_clear(n);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
59
external/flint-2.4.3/examples/delta_qexp.cpp
vendored
Normal file
59
external/flint-2.4.3/examples/delta_qexp.cpp
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2007 David Harvey, William Hart
|
||||
Copyright (C) 2010 Sebastian Pancratz
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for computing the q-expansion of the delta function.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include "fmpzxx.h"
|
||||
#include "arithxx.h"
|
||||
|
||||
using namespace flint;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
slong N = 0;
|
||||
|
||||
if (argc == 2)
|
||||
N = atol(argv[1]);
|
||||
|
||||
if (argc != 2 || N < 1)
|
||||
{
|
||||
flint_printf("Syntax: delta_qexp <integer>\n");
|
||||
flint_printf("where <integer> is the (positive) number of terms to compute\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Coefficient of q^" << N << " is "
|
||||
<< ramanujan_tau(fmpzxx(N)) << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
57
external/flint-2.4.3/examples/fmpq_poly.c
vendored
Normal file
57
external/flint-2.4.3/examples/fmpq_poly.c
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Simple example demonstrating the use of the fmpq_poly module.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fmpq_poly.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char *str, *strf, *strg;
|
||||
fmpq_poly_t f, g;
|
||||
|
||||
fmpq_poly_init(f);
|
||||
fmpq_poly_init(g);
|
||||
fmpq_poly_set_str(f, "2 1/2 3/5");
|
||||
fmpq_poly_set_str(g, "4 1/3 2 3/2 -1/2");
|
||||
strf = fmpq_poly_get_str_pretty(f, "t");
|
||||
strg = fmpq_poly_get_str_pretty(g, "t");
|
||||
fmpq_poly_mul(f, f, g);
|
||||
str = fmpq_poly_get_str_pretty(f, "t");
|
||||
flint_printf("(%s) * (%s) = %s\n", strf, strg, str);
|
||||
flint_free(str);
|
||||
flint_free(strf);
|
||||
flint_free(strg);
|
||||
fmpq_poly_clear(f);
|
||||
fmpq_poly_clear(g);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
45
external/flint-2.4.3/examples/fmpq_poly.cpp
vendored
Normal file
45
external/flint-2.4.3/examples/fmpq_poly.cpp
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Sebastian Pancratz
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Simple example demonstrating the use of the fmpq_polyxx module.
|
||||
*/
|
||||
|
||||
#include "fmpq_polyxx.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace flint;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
fmpq_polyxx f("2 1/2 3/5");
|
||||
fmpq_polyxx g("4 1/3 2 3/2 -1/2");
|
||||
|
||||
std::cout << '(' << f.pretty("t") << ") * (" << g.pretty("t")
|
||||
<< " = " << (f*g).pretty("t") << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
56
external/flint-2.4.3/examples/fmpz_mod_poly.c
vendored
Normal file
56
external/flint-2.4.3/examples/fmpz_mod_poly.c
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Example program for the fmpz_mod_poly module.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
fmpz_t n;
|
||||
fmpz_mod_poly_t x, y;
|
||||
|
||||
fmpz_init_set_ui(n, 7);
|
||||
fmpz_mod_poly_init(x, n);
|
||||
fmpz_mod_poly_init(y, n);
|
||||
fmpz_mod_poly_set_coeff_ui(x, 3, 5);
|
||||
fmpz_mod_poly_set_coeff_ui(x, 0, 6);
|
||||
fmpz_mod_poly_sqr(y, x);
|
||||
fmpz_mod_poly_print(x); flint_printf("\n");
|
||||
fmpz_mod_poly_print(y); flint_printf("\n");
|
||||
fmpz_mod_poly_clear(x);
|
||||
fmpz_mod_poly_clear(y);
|
||||
fmpz_clear(n);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
49
external/flint-2.4.3/examples/fmpz_mod_poly.cpp
vendored
Normal file
49
external/flint-2.4.3/examples/fmpz_mod_poly.cpp
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Example program for the fmpz_mod_poly module.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <fmpz_mod_polyxx.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace flint;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
fmpzxx n(7);
|
||||
fmpz_mod_polyxx x(n);
|
||||
x.set_coeff(3, 5);
|
||||
x.set_coeff(0, 6);
|
||||
|
||||
print(x);flint_printf("\n");
|
||||
print(x.sqr());flint_printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
73
external/flint-2.4.3/examples/fmpz_poly_factor_zassenhaus.c
vendored
Normal file
73
external/flint-2.4.3/examples/fmpz_poly_factor_zassenhaus.c
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Andy Novocin
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Example program demonstrating the Zassenhaus factoring algorithm.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz_poly.h"
|
||||
#include "nmod_poly.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_poly_t f;
|
||||
fmpz_poly_factor_t facs;
|
||||
|
||||
fmpz_poly_init(f);
|
||||
fmpz_poly_factor_init(facs);
|
||||
|
||||
if (0)
|
||||
{
|
||||
FILE *polyfile;
|
||||
polyfile = fopen("examples/fmpz_poly_hensel_P1", "r");
|
||||
|
||||
if (!polyfile)
|
||||
{
|
||||
flint_printf("Error. Could not read P1 from file.\n");
|
||||
abort();
|
||||
}
|
||||
fmpz_poly_fread(polyfile, f);
|
||||
}
|
||||
|
||||
fmpz_poly_set_str(f, "63 1 1 1 -4 -7 -2 -6 -3 -7 18 7 25 -11 95 36 21 16 69 56 35 36 32 33 26 -26 -15 -14 -53 -96 67 72 -67 40 -79 -116 -452 -312 -260 -29 -1393 327 69 -28 -241 230 -54 -309 -125 -74 -450 -69 -3 66 -27 73 68 50 -63 -1290 372 31 -16 2");
|
||||
|
||||
fmpz_poly_factor_zassenhaus(facs, f);
|
||||
|
||||
flint_printf("Polynomial:\n");
|
||||
fmpz_poly_print(f);
|
||||
flint_printf("\nFactorisation:\n");
|
||||
fmpz_poly_factor_print(facs);
|
||||
|
||||
fmpz_poly_clear(f);
|
||||
fmpz_poly_factor_clear(facs);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
63
external/flint-2.4.3/examples/fmpz_poly_factor_zassenhaus.cpp
vendored
Normal file
63
external/flint-2.4.3/examples/fmpz_poly_factor_zassenhaus.cpp
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Andy Novocin
|
||||
Copyright (C) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Example program demonstrating the Zassenhaus factoring algorithm.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "fmpz_polyxx.h"
|
||||
|
||||
using namespace flint;
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
fmpz_polyxx f;
|
||||
|
||||
if (0)
|
||||
{
|
||||
// NB: this does not seem to work in the C version
|
||||
|
||||
FILE *polyfile;
|
||||
polyfile = fopen("examples/fmpz_poly_hensel_P1", "r");
|
||||
|
||||
if (!polyfile)
|
||||
{
|
||||
flint_printf("Error. Could not read P1 from file.\n");
|
||||
abort();
|
||||
}
|
||||
read(polyfile, f);
|
||||
}
|
||||
else
|
||||
f = "63 1 1 1 -4 -7 -2 -6 -3 -7 18 7 25 -11 95 36 21 16 69 56 35 36 32 33 26 -26 -15 -14 -53 -96 67 72 -67 40 -79 -116 -452 -312 -260 -29 -1393 327 69 -28 -241 230 -54 -309 -125 -74 -450 -69 -3 66 -27 73 68 50 -63 -1290 372 31 -16 2";
|
||||
|
||||
flint_printf("Polynomial:\n");print(f);
|
||||
flint_printf("\nFactorisation:\n");print(factor_zassenhaus(f));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
1
external/flint-2.4.3/examples/fmpz_poly_hensel_P1
vendored
Normal file
1
external/flint-2.4.3/examples/fmpz_poly_hensel_P1
vendored
Normal file
File diff suppressed because one or more lines are too long
61
external/flint-2.4.3/examples/fmpz_poly_q.c
vendored
Normal file
61
external/flint-2.4.3/examples/fmpz_poly_q.c
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Simple example demonstrating the use of the fmpz_poly_q module.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_poly.h"
|
||||
#include "fmpz_poly_q.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
char *str, *strf, *strg;
|
||||
fmpz_poly_q_t f, g;
|
||||
|
||||
fmpz_poly_q_init(f);
|
||||
fmpz_poly_q_init(g);
|
||||
fmpz_poly_q_set_str(f, "2 1 3/1 2");
|
||||
fmpz_poly_q_set_str(g, "1 3/2 2 7");
|
||||
strf = fmpz_poly_q_get_str_pretty(f, "t");
|
||||
strg = fmpz_poly_q_get_str_pretty(g, "t");
|
||||
fmpz_poly_q_mul(f, f, g);
|
||||
str = fmpz_poly_q_get_str_pretty(f, "t");
|
||||
flint_printf("%s * %s = %s\n", strf, strg, str);
|
||||
flint_free(str);
|
||||
flint_free(strf);
|
||||
flint_free(strg);
|
||||
fmpz_poly_q_clear(f);
|
||||
fmpz_poly_q_clear(g);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
44
external/flint-2.4.3/examples/fmpz_poly_q.cpp
vendored
Normal file
44
external/flint-2.4.3/examples/fmpz_poly_q.cpp
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Simple example demonstrating the use of the fmpz_poly_q module.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "fmpz_poly_qxx.h"
|
||||
|
||||
using namespace flint;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
fmpz_poly_qxx f("2 1 3/1 2"), g("1 3/2 2 7");
|
||||
std::cout << f.pretty("t") << " * " << g.pretty("t")
|
||||
<< " = " << (f*g).pretty("t") << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
365
external/flint-2.4.3/examples/fooxx.cpp
vendored
Normal file
365
external/flint-2.4.3/examples/fooxx.cpp
vendored
Normal file
@@ -0,0 +1,365 @@
|
||||
/*=============================================================================
|
||||
|
||||
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 Tom Bachmann
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINTXX header to illustrate flintxx extension.
|
||||
*/
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FAKE C DATA TYPE
|
||||
// (This would normally reside in foo.h.)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef FOO_H
|
||||
#define FOO_H
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" { // usually only #ifdef __cplusplus etc
|
||||
typedef slong foo;
|
||||
typedef slong foo_t[1];
|
||||
|
||||
static __inline__ void foo_init(foo_t f)
|
||||
{
|
||||
*f = 0l;
|
||||
}
|
||||
|
||||
static __inline__ void foo_clear(foo_t f)
|
||||
{
|
||||
}
|
||||
|
||||
static __inline__ void foo_set(foo_t to, const foo_t from)
|
||||
{
|
||||
*to = *from;
|
||||
}
|
||||
|
||||
static __inline__ void foo_set_si(foo_t f, slong e)
|
||||
{
|
||||
*f = e;
|
||||
}
|
||||
|
||||
static __inline__ void foo_add(foo_t to, const foo_t e1, const foo_t e2)
|
||||
{
|
||||
*to = *e1 + *e2;
|
||||
}
|
||||
|
||||
static __inline__ void foo_add_si(foo_t to, const foo_t e1, slong e2)
|
||||
{
|
||||
*to = *e1 + e2;
|
||||
}
|
||||
|
||||
static __inline__ int foo_cmp(const foo_t e1, const foo_t e2)
|
||||
{
|
||||
if(*e1 == *e2)
|
||||
return 0;
|
||||
return *e1 > *e2 ? 1 : -1;
|
||||
}
|
||||
|
||||
static __inline__ int foo_is_zero(const foo_t f)
|
||||
{
|
||||
return *f == 0;
|
||||
}
|
||||
|
||||
static __inline__ void foo_magic(foo_t to, const foo_t from)
|
||||
{
|
||||
*to = 2 * (*from) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// C++ wrapper
|
||||
// (This would normally reside in fooxx.h.)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef FOOXX_H
|
||||
#define FOOXX_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "flintxx/expression.h"
|
||||
#include "flintxx/flint_classes.h"
|
||||
|
||||
namespace flint {
|
||||
// fooxx_expression is an "all-purpose" expression template class. In
|
||||
// principle, both Operation and Data can be arbitrary types (Data has to be
|
||||
// copy constructible), but in this generality the objects will be not much
|
||||
// use. In practice, Operation is an empty type, which is just used as a "tag",
|
||||
// and Data is a rather primitive type holding essentially just some payload.
|
||||
// Even more practically speaking, the only instantiations the FLINT developer
|
||||
// should have have to make explicitly are when Operation is
|
||||
// operations::immediate.
|
||||
// The flintxx library will create other instantiations automatically, with
|
||||
// more complicated Data arguments, and different Operation-s.
|
||||
template<class Operation, class Data>
|
||||
class fooxx_expression
|
||||
|
||||
// In order for the flintxx library to do its work, your class must derive from
|
||||
// flint::expression. If your class has just two template parameters Operation
|
||||
// and Data, then the following line is sufficient.
|
||||
: public expression<derived_wrapper<fooxx_expression>, Operation, Data>
|
||||
{
|
||||
public:
|
||||
|
||||
// This line is formulaic, and just makes the base class available.
|
||||
// The typedef is used by the FLINTXX_DEFINE_* macros below, and is
|
||||
// necessary because of namespace injection bugs in gcc<4.5.
|
||||
typedef expression<derived_wrapper< ::flint::fooxx_expression>,
|
||||
Operation, Data> base_t;
|
||||
|
||||
// The next two lines are formulaic, and most likely required in any
|
||||
// concrete class.
|
||||
FLINTXX_DEFINE_BASICS(fooxx_expression)
|
||||
FLINTXX_DEFINE_CTORS(fooxx_expression)
|
||||
|
||||
// This line enables reference types for your class. The second argument is
|
||||
// the underlying C type (note this is foo, not foo_t). The third argument
|
||||
// is the name under which to make the underlying C type available.
|
||||
// All of fooxx, fooxx_ref and fooxx_srcref will have methods _foo() which
|
||||
// can be used to manipulate the underlying C data type.
|
||||
FLINTXX_DEFINE_C_REF(fooxx_expression, foo, _foo)
|
||||
|
||||
// Now custom methods can be added. The typical pattern is to call a C
|
||||
// function with argument this->evaluate()._foo(). The evaluate() method is
|
||||
// inherited from the expression class (this is why it needs to be
|
||||
// qualified by "this"). It obtains a reference to self if self is an
|
||||
// immediate object, and otherwise evaluates self into a temporary
|
||||
// immediate object.
|
||||
// If you leave out the evaluate() step, then the method will only work
|
||||
// on immediates (which may be desirable).
|
||||
bool is_zero() const {return foo_is_zero(this->evaluate()._foo());}
|
||||
};
|
||||
|
||||
// This is formulaic. The class fooxx will be an instantiation of
|
||||
// fooxx_expression, with Operation operations::immediate and Data
|
||||
// detail::foo_data. We need to forward-declare this because of cyclic
|
||||
// dependencies among the immediate types (e.g. fooxx_srcref can be
|
||||
// constructed from fooxx, and vice versa).
|
||||
namespace detail {
|
||||
struct foo_data;
|
||||
}
|
||||
|
||||
// This line just carries out the plan of definition of fooxx explained above.
|
||||
typedef fooxx_expression<operations::immediate, detail::foo_data> fooxx;
|
||||
|
||||
// If you want reference types (i.e. if you had FLINTXX_DEFINE_C_REF above),
|
||||
// these lines are again formulaic.
|
||||
typedef fooxx_expression<operations::immediate,
|
||||
flint_classes::ref_data<fooxx, foo> > fooxx_ref;
|
||||
typedef fooxx_expression<operations::immediate,
|
||||
flint_classes::srcref_data<fooxx, fooxx_ref, foo> > fooxx_srcref;
|
||||
|
||||
namespace detail {
|
||||
|
||||
// We now define the actual immediate Data type. This is not just foo_t (the
|
||||
// underlying C data type), because want it to behave nicely "in a C++ world".
|
||||
struct foo_data
|
||||
{
|
||||
// In general, your data type can contain members and member types in any
|
||||
// way you want. However, to work with the automatic reference type system,
|
||||
// the following three lines are necessary.
|
||||
foo_t inner;
|
||||
typedef foo_t& data_ref_t;
|
||||
typedef const foo_t& data_srcref_t;
|
||||
|
||||
// Default constructor. If this is not provided, fooxx will not be default
|
||||
// constructible (this is OK but requires some additional care, see e.g.
|
||||
// padicxx).
|
||||
foo_data() {foo_init(inner);}
|
||||
|
||||
// Destructor. You most likely want this.
|
||||
~foo_data() {foo_clear(inner);}
|
||||
|
||||
// Copy constructor. You must provide this.
|
||||
foo_data(const foo_data& o)
|
||||
{
|
||||
foo_init(inner);
|
||||
foo_set(inner, o.inner);
|
||||
}
|
||||
|
||||
// Instantiation from srcref. This is basically the same as the copy,
|
||||
// constructor, but unfortunately has to be repeated. This also takes care
|
||||
// of instantiation from ref, since ref->srcref is an implicit conversion
|
||||
// path.
|
||||
foo_data(fooxx_srcref r)
|
||||
{
|
||||
foo_init(inner);
|
||||
foo_set(inner, r._foo());
|
||||
}
|
||||
|
||||
// Now you can add more constructors, or in fact any methods you like.
|
||||
// This one allows constructing fooxx directly from long, int,
|
||||
// unsigned short etc.
|
||||
template<class T>
|
||||
foo_data(T t,
|
||||
typename mp::enable_if<traits::fits_into_slong<T> >::type* = 0)
|
||||
{
|
||||
foo_init(inner);
|
||||
foo_set_si(inner, t);
|
||||
}
|
||||
};
|
||||
} // detail
|
||||
|
||||
// By now our data type is instantiable, but nothing can be done with it.
|
||||
// The flintxx library would be able to create expression templates involving
|
||||
// fooxx, but will not do so because it has no way of evaluating them. We
|
||||
// need to provides evaluation (and other) *rules* to the library. These
|
||||
// (have to) live in namespace flint::rules.
|
||||
//
|
||||
// All possible rules are defined in flintxx/rules.h.
|
||||
|
||||
namespace rules {
|
||||
|
||||
// These two lines are convenient, are not formulaic except that they are used
|
||||
// in all code below.
|
||||
#define FOOXX_COND_S FLINTXX_COND_S(fooxx)
|
||||
#define FOOXX_COND_T FLINTXX_COND_T(fooxx)
|
||||
|
||||
// Define a conditional assignment rule. The general pattern is
|
||||
//
|
||||
// FLINT_DEFINE_DOIT_COND2(name, cond1, cond2, eval).
|
||||
//
|
||||
// This will define a "doit" rule for "name", which takes one input and
|
||||
// one output argument. The result looks something like
|
||||
//
|
||||
// template<class T, class U>
|
||||
// struct assignment<T, U, enable if cond1<T> and cond2<U> are satisfied>
|
||||
// {
|
||||
// static void doit(T& to, const U& from)
|
||||
// eval;
|
||||
// };
|
||||
//
|
||||
// In our case, we are defining an assignment rule, i.e. an explanation on
|
||||
// how to execute operator=. If the right hand side is an expression template,
|
||||
// flintxx will automatically evaluate it first. Thus we need only treat the
|
||||
// case where the LHS is fmpzxx or fmpzxx_ref, and the RHS is fmpzxx, fmpzxx_ref
|
||||
// or fmpzxx_srcref. This is precisely what the conditions FOOXX_COND_T
|
||||
// and FOOXX_COND_S (conditions "fooxx target" and "fooxx source") mean.
|
||||
FLINT_DEFINE_DOIT_COND2(assignment, FOOXX_COND_T, FOOXX_COND_S,
|
||||
foo_set(to._foo(), from._foo()))
|
||||
|
||||
// This line defines assignment of integral PODs to fooxx. Since the underlying
|
||||
// C library only defines fooxx_set_si, we can only safely allow this if the
|
||||
// right hand side can always be losslessly converted into a signed long,
|
||||
// so we use the condition traits::fits_into_slong. Traits are defined all
|
||||
// throughout flintxx, but the most general purpose ones (like fits_into_slong,
|
||||
// is_unsigned_integer etc) can be found in flintxx/traits.h
|
||||
FLINT_DEFINE_DOIT_COND2(assignment, FOOXX_COND_T, traits::fits_into_slong,
|
||||
foo_set_si(to._foo(), from, 1))
|
||||
|
||||
// We now define evaluation rules. In full generality, the rule evaluation<...>
|
||||
// can be used to define how to evaluate any kind of expression. But this is
|
||||
// difficult to use. Moreover, much evaluation logic is shared among most
|
||||
// data types. For example, to evaluate an expression like a + b + c,
|
||||
// one typically first has to evaluate (say) a + b into a temporary t, and then
|
||||
// evaluate t + c. The only step that is specific to fooxx here is how to
|
||||
// add two immediates.
|
||||
// For this reason, flintxx has special convenience forms of the evaluation
|
||||
// rule, called binary and unary expressions. Defining a binary expression
|
||||
// f(x, y) tells flintxx how to evaluate operation "f" on types "x" and "y",
|
||||
// typically immediates. Then flintxx will figure out how to evaluate the
|
||||
// arguments into temporaries first etc.
|
||||
// There is a common special case, when f(x, y) is always the same as f(y, x),
|
||||
// even though x and y may be of different types. Letting flintxx know of this
|
||||
// avoids defining the rule both ways round.
|
||||
//
|
||||
// Here we define a commutative binary expression rule, for operation "plus",
|
||||
// to be executed on to objects of types T and U, both satisfying FOOXX_COND_S.
|
||||
// The result is to be of type foooxx (the second argument).
|
||||
// In this case the types are fully symmetric, so we could have used
|
||||
// FLINT_DEFINE_BINARY_EXPR_COND2 without adverse effects.
|
||||
//
|
||||
// The eval statement should have the effect of to = e1 + e2.
|
||||
FLINT_DEFINE_CBINARY_EXPR_COND2(plus, fooxx, FOOXX_COND_S, FOOXX_COND_S,
|
||||
foo_add(to._foo(), e1._foo(), e2._foo()))
|
||||
|
||||
// Addation of fooxx and PODs. This time CBINARY instead of BINARY is vital.
|
||||
FLINT_DEFINE_CBINARY_EXPR_COND2(plus, fooxx, FOOXX_COND_S,
|
||||
traits::fits_into_slong,
|
||||
foo_add_si(to._foo(), e1._foo(), e2))
|
||||
|
||||
// Next we define relational operators. A convenient way of doing so is using
|
||||
// a "cmp" function, which is handily provided by the underlying C library.
|
||||
// This has a somewhat peculiar signature, so cannot be defined using one of
|
||||
// the standard macros. However, it comes up with many actual FLINT data types,
|
||||
// so we have a special FLINTXX macro just for defining cmp.
|
||||
FLINTXX_DEFINE_CMP(fooxx, foo_cmp(e1._foo(), e2._foo()))
|
||||
|
||||
// Now we define a rule how to print fooxx. There is no macro for this, because
|
||||
// normally instead we define conversion to string, and flintxx takes care of
|
||||
// printing. However, the C library for fooxx provides neither printing nor
|
||||
// conversion to string, so we have to do our own implementation.
|
||||
template<class T>
|
||||
struct print<T, typename mp::enable_if<FOOXX_COND_S<T> >::type>
|
||||
{
|
||||
static void doit(const T& i, std::ostream& o)
|
||||
{
|
||||
o << *i._foo();
|
||||
}
|
||||
};
|
||||
} // rules
|
||||
|
||||
// By now fooxx is a pretty passable wrapper type. In fact the only thing left
|
||||
// to do is to expose foo_magic. This is a special function which can be
|
||||
// executed on instances of foo, and yields another instance of foo. It is
|
||||
// essentially just another unary expression, just with an unusual name, so
|
||||
// this is how we treat it.
|
||||
|
||||
// This line introduces a new type of unary operation, called "magic_op",
|
||||
// together with a function flint::magic(T), which creates expression templates
|
||||
// with this new operation. In principle, any expression template data type is
|
||||
// now allowed to define rules how to performa magic on itself.
|
||||
FLINT_DEFINE_UNOP(magic)
|
||||
|
||||
// Finally, we need to explain how to perform magic on flintxx. This is again
|
||||
// a rule.
|
||||
namespace rules {
|
||||
|
||||
// The pattern should be familiar by now.
|
||||
FLINT_DEFINE_UNARY_EXPR_COND(magic_op, fooxx, FOOXX_COND_S,
|
||||
foo_magic(to._foo(), from._foo()))
|
||||
} // rules
|
||||
} // flint
|
||||
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Example program
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace flint;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
fooxx a, b(4);
|
||||
fooxx_ref ar(a);
|
||||
fooxx_srcref br(b);
|
||||
|
||||
ar = 1 + br + 1; // a=6
|
||||
std::cout << magic(a + (-1)) << '\n'; // 2*(6-1)+1 = 11
|
||||
|
||||
return 0;
|
||||
}
|
||||
160
external/flint-2.4.3/examples/fq_poly.c
vendored
Normal file
160
external/flint-2.4.3/examples/fq_poly.c
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Sebastian Pancratz
|
||||
Copyright (C) 2013 Mike Hansen
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program to demonstrate some use of the fq_poly module.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "fq_poly.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t p;
|
||||
long d, i;
|
||||
fq_ctx_t ctx;
|
||||
clock_t c0, c1;
|
||||
double c;
|
||||
fq_poly_t f, g, h;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
fq_poly_init(f, ctx);
|
||||
fq_poly_init(g, ctx);
|
||||
fq_poly_init(h, ctx);
|
||||
|
||||
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_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_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_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_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_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_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
}
|
||||
|
||||
fq_poly_clear(f, ctx);
|
||||
fq_poly_clear(g, ctx);
|
||||
fq_poly_clear(h, ctx);
|
||||
FLINT_TEST_CLEANUP(state);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
103
external/flint-2.4.3/examples/multi_crt.c
vendored
Normal file
103
external/flint-2.4.3/examples/multi_crt.c
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for balanced multimodular reduction and
|
||||
reconstruction using the Chinese Remainder Theorem.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
slong i;
|
||||
fmpz_t x, y;
|
||||
|
||||
/* Data needed by multi CRT functions */
|
||||
fmpz_comb_t comb;
|
||||
fmpz_comb_temp_t comb_temp;
|
||||
|
||||
mp_limb_t * primes;
|
||||
mp_limb_t * residues;
|
||||
|
||||
slong num_primes;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
flint_printf("Syntax: crt <integer> <num_primes>\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
num_primes = atoi(argv[2]);
|
||||
|
||||
if (num_primes < 1)
|
||||
{
|
||||
flint_printf("Requires num_primes >= 1\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fmpz_init(x);
|
||||
fmpz_init(y);
|
||||
|
||||
fmpz_set_str(x, argv[1], 10);
|
||||
|
||||
primes = flint_malloc(num_primes * sizeof(mp_limb_t));
|
||||
residues = flint_malloc(num_primes * sizeof(mp_limb_t));
|
||||
|
||||
primes[0] = 2;
|
||||
for (i = 1; i < num_primes; i++)
|
||||
primes[i] = n_nextprime(primes[i-1], 0);
|
||||
|
||||
fmpz_comb_init(comb, primes, num_primes);
|
||||
fmpz_comb_temp_init(comb_temp, comb);
|
||||
|
||||
/* Reduce modulo all primes */
|
||||
fmpz_multi_mod_ui(residues, x, comb, comb_temp);
|
||||
|
||||
/* Reconstruct */
|
||||
fmpz_multi_CRT_ui(y, residues, comb, comb_temp, 1);
|
||||
|
||||
for (i = 0; i < num_primes; i++)
|
||||
flint_printf("residue mod %wu = %wu\n", primes[i], residues[i]);
|
||||
|
||||
flint_printf("reconstruction = ");
|
||||
fmpz_print(y);
|
||||
flint_printf("\n");
|
||||
|
||||
fmpz_clear(x);
|
||||
fmpz_clear(y);
|
||||
|
||||
fmpz_comb_temp_clear(comb_temp);
|
||||
fmpz_comb_clear(comb);
|
||||
|
||||
flint_free(residues);
|
||||
flint_free(primes);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
73
external/flint-2.4.3/examples/multi_crt.cpp
vendored
Normal file
73
external/flint-2.4.3/examples/multi_crt.cpp
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Fredrik Johansson
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for balanced multimodular reduction and
|
||||
reconstruction using the Chinese Remainder Theorem.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "fmpzxx.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
using namespace flint;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 3)
|
||||
{
|
||||
std::cerr << "Syntax: crt <integer> <num_primes>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
slong num_primes = atoi(argv[2]);
|
||||
|
||||
if (num_primes < 1)
|
||||
{
|
||||
std::cerr << "Requires num_primes >= 1\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
fmpzxx x(argv[1]);
|
||||
|
||||
std::vector<mp_limb_t> primes(num_primes), residues(num_primes);
|
||||
primes[0] = 2;
|
||||
for (unsigned i = 1; i < num_primes; i++)
|
||||
primes[i] = n_nextprime(primes[i-1], 0);
|
||||
|
||||
fmpz_combxx comb(primes);
|
||||
multi_mod(residues, x, comb);
|
||||
|
||||
for (unsigned i = 0; i < num_primes; i++)
|
||||
std::cout << "residue mod " << primes[i]
|
||||
<< " = " << residues[i] << '\n';
|
||||
|
||||
std::cout << "reconstruction = " << multi_CRT(residues, comb, true)
|
||||
<< '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
164
external/flint-2.4.3/examples/padic.c
vendored
Normal file
164
external/flint-2.4.3/examples/padic.c
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program to demonstrate some use of the padic module.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "padic.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t p;
|
||||
padic_ctx_t ctx;
|
||||
|
||||
char *str;
|
||||
padic_t x, y;
|
||||
|
||||
flint_printf("Output:\n\n");
|
||||
|
||||
/* Case 1 */
|
||||
flint_printf("Positive integer: x = 127 mod 7^10\n");
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, 7);
|
||||
padic_ctx_init(ctx, p, 8, 12, PADIC_TERSE);
|
||||
|
||||
padic_init2(x, 10);
|
||||
padic_set_ui(x, 127, ctx);
|
||||
|
||||
ctx->mode = PADIC_TERSE;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
ctx->mode = PADIC_SERIES;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
ctx->mode = PADIC_VAL_UNIT;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
padic_clear(x);
|
||||
|
||||
padic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
/* Case 2 */
|
||||
flint_printf("Positive integer larger than p^N: x = 1057 mod 2^10\n");
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, 2);
|
||||
padic_ctx_init(ctx, p, 10, 12, PADIC_TERSE);
|
||||
|
||||
padic_init2(x, 10);
|
||||
padic_set_ui(x, 1057, ctx);
|
||||
|
||||
ctx->mode = PADIC_TERSE;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
ctx->mode = PADIC_SERIES;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
ctx->mode = PADIC_VAL_UNIT;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
padic_clear(x);
|
||||
|
||||
padic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
/* Case 3 */
|
||||
flint_printf("Negative integer: x = -127 mod 3^10\n");
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, 3);
|
||||
padic_ctx_init(ctx, p, 10, 12, PADIC_TERSE);
|
||||
|
||||
padic_init2(x, 10);
|
||||
padic_set_si(x, -127, ctx);
|
||||
|
||||
ctx->mode = PADIC_TERSE;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
ctx->mode = PADIC_VAL_UNIT;
|
||||
str = padic_get_str(NULL, x, ctx);
|
||||
flint_printf("print: "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("get_str: %s\n", str);
|
||||
flint_free(str);
|
||||
|
||||
padic_clear(x);
|
||||
|
||||
padic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
/* Log */
|
||||
flint_printf("Log of 7380996 mod 5^20\n");
|
||||
|
||||
fmpz_init(p);
|
||||
fmpz_set_ui(p, 5);
|
||||
padic_ctx_init(ctx, p, 10, 25, PADIC_SERIES);
|
||||
|
||||
padic_init(x);
|
||||
padic_init(y);
|
||||
padic_set_ui(x, 7380996, ctx);
|
||||
|
||||
padic_log(y, x, ctx);
|
||||
|
||||
flint_printf("x = "), padic_print(x, ctx), flint_printf("\n");
|
||||
flint_printf("y = "), padic_print(y, ctx), flint_printf("\n");
|
||||
|
||||
padic_clear(x);
|
||||
padic_clear(y);
|
||||
|
||||
padic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
116
external/flint-2.4.3/examples/padic.cpp
vendored
Normal file
116
external/flint-2.4.3/examples/padic.cpp
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Sebastian Pancratz
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program to demonstrate some use of the padic module.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "padicxx.h"
|
||||
|
||||
using namespace flint;
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Output:\n\n";
|
||||
|
||||
// Case 1
|
||||
{
|
||||
std::cout << "Positive integer: x = 127 mod 7^10\n";
|
||||
fmpzxx p(7);
|
||||
padicxx_ctx ctx(p, 8, 12, PADIC_TERSE);
|
||||
padicxx x = padicxx::from_QQ(127, ctx, 10);
|
||||
|
||||
ctx.mode() = PADIC_TERSE;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
|
||||
ctx.mode() = PADIC_SERIES;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
|
||||
ctx.mode() = PADIC_VAL_UNIT;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
}
|
||||
|
||||
// Case 2
|
||||
{
|
||||
std::cout << "Positive integer larger than p^N: x = 1057 mod 2^10\n";
|
||||
fmpzxx p(2);
|
||||
padicxx_ctx ctx(p, 10, 12, PADIC_TERSE);
|
||||
padicxx x = padicxx::from_QQ(1057, ctx, 10);
|
||||
|
||||
ctx.mode() = PADIC_TERSE;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
|
||||
ctx.mode() = PADIC_SERIES;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
|
||||
ctx.mode() = PADIC_VAL_UNIT;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
}
|
||||
|
||||
// Case 3
|
||||
{
|
||||
std::cout << "Negative integer: x = -127 mod 3^10\n";
|
||||
fmpzxx p(3);
|
||||
padicxx_ctx ctx(p, 10, 12, PADIC_TERSE);
|
||||
padicxx x = padicxx::from_QQ(-127, ctx, 10);
|
||||
|
||||
ctx.mode() = PADIC_TERSE;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
|
||||
ctx.mode() = PADIC_SERIES;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
|
||||
ctx.mode() = PADIC_VAL_UNIT;
|
||||
std::cout << "print: ";print(x);std::cout << '\n';
|
||||
std::cout << "get_str: " << x.to_string() << '\n';
|
||||
}
|
||||
|
||||
// Log
|
||||
{
|
||||
std::cout << "Log of 7380996 mod 5^20\n";
|
||||
fmpzxx p(5);
|
||||
padicxx_ctx ctx(p, 10, 25, PADIC_SERIES);
|
||||
|
||||
padicxx x = padicxx::from_QQ(7380996, ctx);
|
||||
padicxx y(log(x));
|
||||
|
||||
std::cout << "x = " << x << '\n';
|
||||
std::cout << "y = " << y << '\n';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
30
external/flint-2.4.3/examples/partitions.c
vendored
Normal file
30
external/flint-2.4.3/examples/partitions.c
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#include <gmp.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "arith.h"
|
||||
|
||||
int
|
||||
main(int argc, char * argv[])
|
||||
{
|
||||
fmpz_t x;
|
||||
ulong n;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
flint_printf("usage: partitions n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
flint_sscanf(argv[1], "%wu", &n);
|
||||
|
||||
flint_printf("p(%wu) = \n", n);
|
||||
|
||||
fmpz_init(x);
|
||||
arith_number_of_partitions(x, n);
|
||||
fmpz_print(x);
|
||||
flint_printf("\n");
|
||||
fmpz_clear(x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
24
external/flint-2.4.3/examples/partitions.cpp
vendored
Normal file
24
external/flint-2.4.3/examples/partitions.cpp
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "arithxx.h"
|
||||
#include "fmpzxx.h"
|
||||
|
||||
using namespace flint;
|
||||
using namespace std;
|
||||
|
||||
int
|
||||
main(int argc, char * argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cerr << "usage: partitions n\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
ulong n;
|
||||
flint_sscanf(argv[1], "%wu", &n);
|
||||
|
||||
std::cout << "p(" << n << ") =\n" << number_of_partitions(n) << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
69
external/flint-2.4.3/examples/primegen.c
vendored
Normal file
69
external/flint-2.4.3/examples/primegen.c
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "flint.h"
|
||||
#include "ulong_extras.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
n_primes_t iter;
|
||||
mp_limb_t p, N;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
flint_printf("primegen N - print all primes <= N\n");
|
||||
flint_printf("primegen -c N - generate the primes but just count them\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
N = strtoul(argv[argc-1], NULL, 10);
|
||||
if (N == UWORD_MAX)
|
||||
{
|
||||
flint_printf("N must be smaller than %wu\n", UWORD_MAX);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
ulong count = 0;
|
||||
n_primes_init(iter);
|
||||
while ((p = n_primes_next(iter)) <= N)
|
||||
count++;
|
||||
n_primes_clear(iter);
|
||||
flint_printf("pi(%wu) = %wu\n", N, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
n_primes_init(iter);
|
||||
while ((p = n_primes_next(iter)) <= N)
|
||||
flint_printf("%wu\n", p);
|
||||
n_primes_clear(iter);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
174
external/flint-2.4.3/examples/qadic.c
vendored
Normal file
174
external/flint-2.4.3/examples/qadic.c
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011, 2013 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program to demonstrate some use of the qadic module.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "qadic.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
fmpz_t p;
|
||||
slong d, N;
|
||||
qadic_ctx_t ctx;
|
||||
|
||||
qadic_t a, b, c;
|
||||
|
||||
int ans;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
fmpz_t e = {WORD(4)};
|
||||
fmpz_t nine = {WORD(9)};
|
||||
|
||||
fmpz_init_set_ui(p, 3);
|
||||
d = 2;
|
||||
N = 5;
|
||||
qadic_ctx_init_conway(ctx, p, d, 0, N, "a", PADIC_SERIES);
|
||||
|
||||
qadic_init2(a, N);
|
||||
qadic_init2(b, N);
|
||||
qadic_init2(c, N);
|
||||
|
||||
flint_printf("Compute a power and a sum\n");
|
||||
padic_poly_fit_length(a, 2);
|
||||
fmpz_one(a->coeffs + 0);
|
||||
fmpz_set_ui(a->coeffs + 1, 2);
|
||||
a->val = 0;
|
||||
_padic_poly_set_length(a, 2);
|
||||
|
||||
qadic_print_pretty(a, ctx); flint_printf("\n");
|
||||
|
||||
qadic_pow(a, a, e, ctx);
|
||||
padic_poly_set_ui(b, 3249, &ctx->pctx);
|
||||
qadic_add(c, a, b, ctx);
|
||||
|
||||
qadic_print_pretty(a, ctx); flint_printf("\n");
|
||||
qadic_print_pretty(b, ctx); flint_printf("\n");
|
||||
qadic_print_pretty(c, ctx); flint_printf("\n");
|
||||
flint_printf("\n");
|
||||
|
||||
flint_printf("Compute a Teichmuller lift\n");
|
||||
padic_poly_fit_length(a, 2);
|
||||
fmpz_one(a->coeffs + 0);
|
||||
fmpz_set_ui(a->coeffs + 1, 2);
|
||||
a->val = 0;
|
||||
_padic_poly_set_length(a, 2);
|
||||
|
||||
qadic_teichmuller(b, a, ctx);
|
||||
qadic_pow(c, b, nine, ctx);
|
||||
|
||||
qadic_print_pretty(a, ctx); flint_printf("\n");
|
||||
qadic_print_pretty(b, ctx); flint_printf("\n");
|
||||
qadic_print_pretty(c, ctx); flint_printf("\n");
|
||||
flint_printf("\n");
|
||||
|
||||
flint_printf("Compute an inverse\n");
|
||||
qadic_set(a, b, ctx);
|
||||
qadic_inv(b, a, ctx);
|
||||
qadic_mul(c, a, b, ctx);
|
||||
|
||||
qadic_print_pretty(a, ctx); flint_printf("\n");
|
||||
qadic_print_pretty(b, ctx); flint_printf("\n");
|
||||
qadic_print_pretty(c, ctx); flint_printf("\n");
|
||||
flint_printf("\n");
|
||||
|
||||
qadic_clear(a);
|
||||
qadic_clear(b);
|
||||
qadic_clear(c);
|
||||
|
||||
qadic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
flint_printf("Compute a Frobenius image\n");
|
||||
|
||||
fmpz_init_set_ui(p, 3);
|
||||
d = 2;
|
||||
N = 5;
|
||||
qadic_ctx_init_conway(ctx, p, d, 0, N, "X", PADIC_TERSE);
|
||||
|
||||
qadic_init2(a, N);
|
||||
qadic_init2(b, N);
|
||||
|
||||
padic_poly_fit_length(a, 2);
|
||||
a->coeffs[0] = WORD(78);
|
||||
a->coeffs[1] = WORD(45);
|
||||
a->val = 0;
|
||||
_padic_poly_set_length(a, 2);
|
||||
|
||||
qadic_frobenius(b, a, 1, ctx);
|
||||
flint_printf("a = "), qadic_print_pretty(a, ctx), flint_printf("\n");
|
||||
flint_printf("b = "), qadic_print_pretty(b, ctx), flint_printf("\n");
|
||||
flint_printf("Context:\n"), qadic_ctx_print(ctx);
|
||||
flint_printf("\n");
|
||||
|
||||
qadic_clear(a);
|
||||
qadic_clear(b);
|
||||
|
||||
qadic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
flint_printf("Compute a square root\n");
|
||||
|
||||
fmpz_init_set_ui(p, 2);
|
||||
d = 3;
|
||||
N = 2;
|
||||
qadic_ctx_init_conway(ctx, p, d, 0, N, "X", PADIC_SERIES);
|
||||
|
||||
qadic_init2(a, N);
|
||||
qadic_init2(b, N);
|
||||
|
||||
padic_poly_fit_length(a, d);
|
||||
a->coeffs[0] = WORD(1);
|
||||
a->coeffs[1] = WORD(3);
|
||||
a->coeffs[2] = WORD(1);
|
||||
a->val = 0;
|
||||
_padic_poly_set_length(a, d);
|
||||
|
||||
ans = qadic_sqrt(b, a, ctx);
|
||||
flint_printf("a = "), qadic_print_pretty(a, ctx), flint_printf("\n");
|
||||
flint_printf("b = "), qadic_print_pretty(b, ctx), flint_printf("\n");
|
||||
flint_printf("ans = %d\n", ans);
|
||||
flint_printf("Context:\n"), qadic_ctx_print(ctx);
|
||||
flint_printf("\n");
|
||||
|
||||
qadic_clear(a);
|
||||
qadic_clear(b);
|
||||
|
||||
qadic_ctx_clear(ctx);
|
||||
fmpz_clear(p);
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
139
external/flint-2.4.3/examples/radix.c
vendored
Normal file
139
external/flint-2.4.3/examples/radix.c
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Sebastian Pancratz
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program to demonstrate some use of the
|
||||
function fmpz_mod_poly_radix() for radix conversion
|
||||
over $\mathbf{Z}/n \mathbf{Z}$.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <gmp.h>
|
||||
|
||||
#include "flint.h"
|
||||
#include "fmpz_mod_poly.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const slong n = 12376;
|
||||
const slong N = n / 26;
|
||||
|
||||
clock_t c0, c1;
|
||||
double c;
|
||||
|
||||
slong i;
|
||||
fmpz_t a, m;
|
||||
fmpz_mod_poly_t A, B, r, t;
|
||||
fmpz_mod_poly_radix_t S;
|
||||
fmpz_mod_poly_struct **b;
|
||||
|
||||
FLINT_TEST_INIT(state);
|
||||
|
||||
fmpz_init(a);
|
||||
fmpz_init(m);
|
||||
|
||||
fmpz_set_ui(m, 17);
|
||||
fmpz_pow_ui(m, m, 26);
|
||||
|
||||
fmpz_mod_poly_init(A, m);
|
||||
fmpz_mod_poly_init(B, m);
|
||||
fmpz_mod_poly_init(r, m);
|
||||
fmpz_mod_poly_init(t, m);
|
||||
|
||||
fmpz_mod_poly_set_coeff_ui(A, 3, 5);
|
||||
fmpz_mod_poly_set_coeff_ui(A, 4, 4);
|
||||
|
||||
fmpz_mod_poly_set_coeff_ui(B, 0, 1);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 2, 1);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 3, 5);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 4, 1);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 5, 5);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 8, 8);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 9, 8);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 10, 5);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 12, 6);
|
||||
fmpz_mod_poly_set_coeff_ui(B, 13, 1);
|
||||
|
||||
fmpz_mod_poly_pow(r, A, 3);
|
||||
fmpz_set_ui(a, 4);
|
||||
fmpz_mod_poly_scalar_mul_fmpz(r, r, a);
|
||||
|
||||
fmpz_mod_poly_pow(t, B, 2);
|
||||
fmpz_set_ui(a, 27);
|
||||
fmpz_mod_poly_scalar_mul_fmpz(t, t, a);
|
||||
|
||||
fmpz_mod_poly_add(r, r, t);
|
||||
|
||||
b = flint_malloc((N + 1) * sizeof(fmpz_mod_poly_struct *));
|
||||
for (i = 0; i <= N; i++)
|
||||
{
|
||||
b[i] = flint_malloc(sizeof(fmpz_mod_poly_struct));
|
||||
fmpz_mod_poly_init(b[i], m);
|
||||
}
|
||||
|
||||
fmpz_mod_poly_randtest(t, state, n + 1);
|
||||
|
||||
flint_printf("Radix conversion\n");
|
||||
flint_printf("----------------\n");
|
||||
flint_printf(" Degree of the radix: %wd\n", fmpz_mod_poly_degree(r));
|
||||
flint_printf(" Bit size of the modulus: %wd\n", (slong) fmpz_bits(fmpz_mod_poly_modulus(r)));
|
||||
flint_printf(" Degree of the input: %wd\n", fmpz_mod_poly_degree(t));
|
||||
|
||||
c0 = clock();
|
||||
fmpz_mod_poly_radix_init(S, r, n + 1);
|
||||
c1 = clock();
|
||||
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
|
||||
|
||||
flint_printf(" Precomputation: %fs\n", c);
|
||||
|
||||
c0 = clock();
|
||||
fmpz_mod_poly_radix(b, t, S);
|
||||
c1 = clock();
|
||||
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
|
||||
|
||||
flint_printf(" Conversion: %fs\n", c);
|
||||
|
||||
fmpz_clear(a);
|
||||
fmpz_clear(m);
|
||||
fmpz_mod_poly_clear(A);
|
||||
fmpz_mod_poly_clear(B);
|
||||
fmpz_mod_poly_clear(r);
|
||||
fmpz_mod_poly_clear(t);
|
||||
fmpz_mod_poly_radix_clear(S);
|
||||
|
||||
for (i = 0; i <= N; i++)
|
||||
{
|
||||
fmpz_mod_poly_clear(b[i]);
|
||||
flint_free(b[i]);
|
||||
}
|
||||
flint_free(b);
|
||||
|
||||
flint_randclear(state);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
94
external/flint-2.4.3/examples/radix.cpp
vendored
Normal file
94
external/flint-2.4.3/examples/radix.cpp
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2012 Sebastian Pancratz
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program to demonstrate some use of the
|
||||
function fmpz_mod_poly_radix() for radix conversion
|
||||
over $\mathbf{Z}/n \mathbf{Z}$.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include "fmpz_mod_polyxx.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace flint;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const slong n = 12376;
|
||||
const slong N = n / 26;
|
||||
|
||||
frandxx state;
|
||||
|
||||
fmpzxx m(17);
|
||||
m = m.pow(26u);
|
||||
|
||||
fmpz_mod_polyxx A(m), B(m);
|
||||
|
||||
A.set_coeff(3, 5);
|
||||
A.set_coeff(4, 4);
|
||||
|
||||
B.set_coeff(0, 1);
|
||||
B.set_coeff(2, 1);
|
||||
B.set_coeff(3, 5);
|
||||
B.set_coeff(4, 1);
|
||||
B.set_coeff(5, 5);
|
||||
B.set_coeff(8, 8);
|
||||
B.set_coeff(9, 8);
|
||||
B.set_coeff(10, 5);
|
||||
B.set_coeff(12, 6);
|
||||
B.set_coeff(13, 1);
|
||||
|
||||
fmpz_mod_polyxx r(A.pow(3u) * fmpzxx(4) + B.pow(2u) * fmpzxx(27));
|
||||
|
||||
fmpz_mod_poly_vecxx b(N + 1, m);
|
||||
|
||||
fmpz_mod_polyxx t = fmpz_mod_polyxx::randtest(m, state, n + 1);
|
||||
|
||||
flint_printf("Radix conversion\n");
|
||||
flint_printf("----------------\n");
|
||||
flint_printf(" Degree of the radix: %wd\n", r.degree());
|
||||
flint_printf(" Bit size of the modulus: %wd\n", (slong) bits(r.modulus()));
|
||||
flint_printf(" Degree of the input: %wd\n", t.degree());
|
||||
|
||||
clock_t c0 = clock();
|
||||
fmpz_mod_poly_radixxx S(r, n + 1);
|
||||
clock_t c1 = clock();
|
||||
double c = (double) (c1 - c0) / CLOCKS_PER_SEC;
|
||||
|
||||
flint_printf(" Precomputation: %fs\n", c);
|
||||
|
||||
c0 = clock();
|
||||
b = t.radix(S);
|
||||
c1 = clock();
|
||||
c = (double) (c1 - c0) / CLOCKS_PER_SEC;
|
||||
|
||||
flint_printf(" Conversion: %fs\n", c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
76
external/flint-2.4.3/examples/stirling_matrix.c
vendored
Normal file
76
external/flint-2.4.3/examples/stirling_matrix.c
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Fredrik Johansson
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for generating Stirling number matrices
|
||||
and inverting them.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "flint.h"
|
||||
#include "fmpz.h"
|
||||
#include "fmpz_mat.h"
|
||||
#include "arith.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
slong n;
|
||||
fmpz_mat_t S1, S2, P;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
flint_printf("Syntax: stirling_matrix <integer>\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
n = atoi(argv[1]);
|
||||
|
||||
fmpz_mat_init(S1, n, n);
|
||||
fmpz_mat_init(S2, n, n);
|
||||
fmpz_mat_init(P, n, n);
|
||||
|
||||
arith_stirling_matrix_1(S1);
|
||||
arith_stirling_matrix_2(S2);
|
||||
fmpz_mat_mul(P, S1, S2);
|
||||
|
||||
flint_printf("S1 [Stirling numbers of 1st kind]:\n");
|
||||
fmpz_mat_print_pretty(S1);
|
||||
flint_printf("\n\n");
|
||||
|
||||
flint_printf("S2 [Stirling numbers of 2nd kind]:\n");
|
||||
fmpz_mat_print_pretty(S2);
|
||||
flint_printf("\n\n");
|
||||
|
||||
flint_printf("S1 * S2:\n");
|
||||
fmpz_mat_print_pretty(P);
|
||||
flint_printf("\n\n");
|
||||
|
||||
fmpz_mat_clear(S1);
|
||||
fmpz_mat_clear(S2);
|
||||
fmpz_mat_clear(P);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
65
external/flint-2.4.3/examples/stirling_matrix.cpp
vendored
Normal file
65
external/flint-2.4.3/examples/stirling_matrix.cpp
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
/*=============================================================================
|
||||
|
||||
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) 2011 Fredrik Johansson
|
||||
Copyright (C) 2013 Tom Bachmann (C++ adaptation)
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
Demo FLINT program for generating Stirling number matrices
|
||||
and inverting them.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include "fmpz_matxx.h"
|
||||
#include "fmpzxx.h"
|
||||
#include "arithxx.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace flint;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
flint_printf("Syntax: stirling_matrix <integer>\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
slong n = atoi(argv[1]);
|
||||
|
||||
fmpz_matxx S1(stirling_matrix_1(n, n)), S2(stirling_matrix_2(n, n));
|
||||
|
||||
flint_printf("S1 [Stirling numbers of 1st kind]:\n");
|
||||
print_pretty(S1);
|
||||
flint_printf("\n\n");
|
||||
|
||||
flint_printf("S2 [Stirling numbers of 2nd kind]:\n");
|
||||
print_pretty(S2);
|
||||
flint_printf("\n\n");
|
||||
|
||||
flint_printf("S1 * S2:\n");
|
||||
print_pretty(S1*S2);
|
||||
flint_printf("\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user