1 /*
2 test file for tree functions
3
4 Copyright (C) 2011, 2012 Andreas Enge
5
6 This file is part of the MPFRCX Library.
7
8 The MPFRCX Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12
13 The MPFRCX Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with the MPFRCX library; see the file COPYING.LESSER. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 MA 02111-1307, USA.
22 */
23
24 #include <stdio.h>
25 #include "mpfrcx.h"
26
27
check_reconstruct_multieval()28 static void check_reconstruct_multieval () {
29
30 const int n=12;
31 const mpfr_prec_t prec = 100;
32 int i;
33 mpc_t *values, *args;
34 mpcx_t f;
35
36 values = (mpc_t *) malloc (n * sizeof (mpc_t));
37 args = (mpc_t *) malloc (n * sizeof (mpc_t));
38 for (i = 0; i < n; i++) {
39 mpc_init2 (values [i], prec);
40 mpc_init2 (args [i], prec);
41 mpc_set_ui (args [i], (unsigned long int) i, MPC_RNDNN);
42 }
43
44 mpcx_init (f, n+1, prec);
45 mpcx_reconstruct_from_roots (f, args, n);
46 mpcx_multieval (values, args, n, f);
47 mpcx_clear (f);
48
49 for (i = 0; i < n; i++) {
50 if (mpc_cmp (values [i], args [0]) != 0) {
51 fprintf (stderr, "Error in reconstruct or multieval: Value should be 0, but is\n");
52 mpc_out_str (stdout, 10, 0, values [i], MPC_RNDNN);
53 fprintf (stderr, "\n");
54 exit (1);
55 }
56 mpc_clear (values [i]);
57 mpc_clear (args [i]);
58 }
59 free (values);
60 free (args);
61 }
62
63
64 static void
check_hecke(void)65 check_hecke (void) {
66 const mpfr_prec_t prec = 100;
67 int i, j;
68 mpcx_t factor [3], f;
69 mpcx_tree_t subprods;
70 mpcx_t val [3], res;
71 mpcx_t **vals, *ress;
72
73 mpcx_init (f, 5, prec);
74 mpcx_init (res, 4, prec);
75 for (j = 0; j < 3; j++) {
76 mpcx_init (factor [j], 3, prec);
77 mpcx_init (val [j], 2, prec);
78 }
79 ress = (mpcx_t *) malloc (3 * sizeof (mpcx_t));
80 vals = (mpcx_t **) malloc (3 * sizeof (mpcx_t *));
81 for (i = 0; i < 3; i++) {
82 mpcx_init (ress [i], 5, prec);
83 vals [i] = (mpcx_t *) malloc (3 * sizeof (mpcx_t));
84 for (j = 0; j < 3; j++)
85 mpcx_init (vals [i][j], 3, prec);
86 }
87 mpcx_tree_init (subprods, 3, prec);
88
89 mpcx_set_deg (factor [0], 2);
90 mpc_set_ui (factor [0]->coeff [2], 1ul, MPC_RNDNN);
91 mpc_set_ui (factor [0]->coeff [1], 0ul, MPC_RNDNN);
92 mpc_set_ui (factor [0]->coeff [0], 1ul, MPC_RNDNN);
93 mpcx_set_deg (factor [1], 1);
94 mpc_set_ui (factor [1]->coeff [1], 1ul, MPC_RNDNN);
95 mpc_set_si (factor [1]->coeff [0], -1l, MPC_RNDNN);
96 mpcx_set_deg (factor [2], 1);
97 mpc_set_ui (factor [2]->coeff [1], 1ul, MPC_RNDNN);
98 mpc_set_si (factor [2]->coeff [0], -2l, MPC_RNDNN);
99 mpcx_set_deg (val [0], 1);
100 mpc_set_ui (val [0]->coeff [1], 2ul, MPC_RNDNN);
101 mpc_set_si (val [0]->coeff [0], -2l, MPC_RNDNN);
102 mpcx_set_deg (val [1], 0);
103 mpc_set_ui (val [1]->coeff [0], 3ul, MPC_RNDNN);
104 mpcx_set_deg (val [2], 0);
105 mpc_set_ui (val [2]->coeff [0], 4ul, MPC_RNDNN);
106 mpcx_set_deg (res, 3);
107 mpc_set_ui (res->coeff [3], 9ul, MPC_RNDNN);
108 mpc_set_si (res->coeff [2], -18l, MPC_RNDNN);
109 mpc_set_ui (res->coeff [1], 17ul, MPC_RNDNN);
110 mpc_set_si (res->coeff [0], -14l, MPC_RNDNN);
111
112 mpcx_subproducttree (subprods, factor);
113 mpcx_hecke (f, subprods, val);
114
115 if (mpcx_cmp (f, res) != 0) {
116 fprintf (stderr, "Error in hecke\n");
117 printf ("f "); mpcx_out_str (stdout, 10, 0, f); printf ("\n");
118 printf ("res "); mpcx_out_str (stdout, 10, 0, res); printf ("\n");
119 exit (1);
120 }
121
122 for (j = 0; j < 3; j++)
123 mpcx_set (vals [0][j], factor [j]);
124 for (i = 1; i < 3; i++)
125 for (j = 0; j < 3; j++)
126 mpcx_set (vals [i][j], val [j]);
127
128 mpcx_product_and_hecke (ress, vals, 3, 3);
129 mpcx_tree_get_root (f, subprods);
130 if (mpcx_cmp (f, ress [0]) != 0) {
131 fprintf (stderr, "Error in product_and_hecke\n");
132 printf ("f "); mpcx_out_str (stdout, 10, 0, f); printf ("\n");
133 printf ("ress [0] "); mpcx_out_str (stdout, 10, 0, ress [0]); printf ("\n");
134 exit (1);
135 }
136 if (mpcx_cmp (res, ress [1]) != 0) {
137 fprintf (stderr, "Error in product_and_hecke\n");
138 printf ("res "); mpcx_out_str (stdout, 10, 0, res); printf ("\n");
139 printf ("ress [1] "); mpcx_out_str (stdout, 10, 0, ress [1]); printf ("\n");
140 exit (1);
141 }
142 if (mpcx_cmp (res, ress [2]) != 0) {
143 fprintf (stderr, "Error in product_and_hecke\n");
144 printf ("res "); mpcx_out_str (stdout, 10, 0, res); printf ("\n");
145 printf ("ress [2] "); mpcx_out_str (stdout, 10, 0, ress [2]); printf ("\n");
146 exit (1);
147 }
148
149 mpcx_clear (f);
150 mpcx_clear (res);
151 for (j = 0; j < 3; j++) {
152 mpcx_clear (factor [j]);
153 mpcx_clear (val [j]);
154 }
155 for (i = 0; i < 3; i++) {
156 mpcx_clear (ress [i]);
157 for (j = 0; j < 3; j++)
158 mpcx_clear (vals [i][j]);
159 free (vals [i]);
160 }
161 free (ress);
162 free (vals);
163 mpcx_tree_clear (subprods);
164 }
165
166
main(void)167 int main (void) {
168
169 check_reconstruct_multieval ();
170 check_hecke ();
171
172 return 0;
173 }
174