MPSolve  3.2.1
types.h
1 #ifndef MPS_TYPES_H_
2 #define MPS_TYPES_H_
3 
4 /* String type used for some hacks */
5 typedef const char * mps_string;
6 
7 /* Boolean type used in MPSolve */
8 #ifndef __MPS_NOT_DEFINE_BOOL
9 typedef enum
10 { false = 0, true = 1 } mps_boolean;
11 #else
12 /* Small workaround to make matlab module work; there is,
13  * int matlab headers, already a false keyword defined, so
14  * reusing it here make compilation fail. */
15 typedef bool mps_boolean;
16 #endif /* mps_boolean */
17 
18 #define mps_boolean_to_string(x) ((x) == true) ? "true" : "false"
19 
20 /* Debug level */
21 typedef int mps_debug_level;
22 
23 /* Handle systems where isnan and isinf are not available */
24 #include <math.h>
25 #ifndef isnan
26  # define isnan(x) \
27  (sizeof(x) == sizeof(long double) ? isnan_ld (x) \
28  : sizeof(x) == sizeof(double) ? isnan_d (x) \
29  : isnan_f (x))
30 static inline int isnan_f (float x)
31 {
32  return x != x;
33 }
34 static inline int isnan_d (double x)
35 {
36  return x != x;
37 }
38 static inline int isnan_ld (long double x)
39 {
40  return x != x;
41 }
42  #endif
43 
44 #ifndef isinf
45  # define isinf(x) \
46  (sizeof(x) == sizeof(long double) ? isinf_ld (x) \
47  : sizeof(x) == sizeof(double) ? isinf_d (x) \
48  : isinf_f (x))
49 static inline int isinf_f (float x)
50 {
51  return !isnan (x) && isnan (x - x);
52 }
53 static inline int isinf_d (double x)
54 {
55  return !isnan (x) && isnan (x - x);
56 }
57 static inline int isinf_ld (long double x)
58 {
59  return !isnan (x) && isnan (x - x);
60 }
61 #endif
62 
63 #include <mps/mt-types.h>
64 
65 #ifdef __cplusplus
66 
67 /* Forward declarations of the type used in the headers, so they can be
68  * resolved indepently by the header inclusion order. */
69 
70 /* context.h */
71 struct mps_context;
72 
73 /* cluster.h */
74 struct mps_root;
75 struct mps_cluster;
76 struct mps_cluster_item;
77 struct mps_clusterization;
78 
79 /* secular-equation.h */
82 
83 /* monomial-poly.h */
84 struct mps_monomial_poly;
85 
86 /* monomial-matrix-poly.h */
88 
89 /* polynomial.h */
90 struct mps_polynomial;
91 
92 /* input-buffer.h */
93 struct mps_input_buffer;
94 
95 /* approximation.h */
96 struct mps_approximation;
97 
98 /* options.h */
99 struct mps_opt;
100 struct mps_input_option;
103 
104 /* list.h */
105 struct mps_list_element;
106 struct mps_list;
107 
110 
111 /* threading.h */
112 struct mps_thread_job;
113 struct mps_thread_job_queue;
115 struct mps_thread;
116 struct mps_thread_pool;
117 struct mps_thread_pool_queue;
119 
120 /* regeneration-driver.h */
122 
123 #else
124 
125 /* Forward declarations of the type used in the headers, so they can be
126  * resolved indepently by the header inclusion order. */
127 
128 /* context.h */
129 typedef struct mps_context mps_context;
130 
131 /* cluster.h */
132 typedef struct mps_root mps_root;
133 typedef struct mps_cluster mps_cluster;
134 typedef struct mps_cluster_item mps_cluster_item;
136 
137 /* secular-equation.h */
140 
141 /* monomial-poly.h */
142 typedef struct mps_monomial_poly mps_monomial_poly;
143 
144 /* monomial-matrix-poly.h */
146 
147 /* polynomial.h */
148 typedef struct mps_polynomial mps_polynomial;
149 
150 /* input-buffer.h */
151 typedef struct mps_input_buffer mps_input_buffer;
152 
153 /* approximation.h */
154 typedef struct mps_approximation mps_approximation;
155 
156 /* options.h */
157 typedef struct mps_opt mps_opt;
158 typedef struct mps_input_option mps_input_option;
161 
162 /* list.h */
163 typedef struct mps_list_element mps_list_element;
164 typedef struct mps_list mps_list;
165 
166 typedef enum mps_root_status mps_root_status;
167 typedef enum mps_root_inclusion mps_root_inclusion;
168 typedef enum mps_root_attrs mps_root_attrs;
169 
170 typedef enum mps_algorithm mps_algorithm;
171 typedef enum mps_operation mps_operation;
172 typedef enum mps_option_key mps_option_key;
173 typedef enum mps_structure mps_structure;
174 typedef enum mps_representation mps_representation;
175 typedef enum mps_density mps_density;
176 typedef enum mps_output_format mps_output_format;
177 typedef enum mps_output_goal mps_output_goal;
178 typedef enum mps_search_set mps_search_set;
179 typedef enum mps_phase mps_phase;
180 typedef enum mps_starting_strategy mps_starting_strategy;
181 
184 
185 /* threading.h */
186 typedef struct mps_thread_job mps_thread_job;
189 typedef struct mps_thread mps_thread;
190 typedef struct mps_thread_pool mps_thread_pool;
193 
194 /* regeneration-driver.h */
196 
197 #endif
198 
208 enum mps_phase {
209  no_phase, float_phase, dpe_phase, mp_phase
210 };
211 
212 static const mps_string mps_phase_string [] = {
213  "No phase", "Float phase", "DPE phase", "MP phase"
214 };
215 #define MPS_PHASE_TO_STRING(phase) (mps_phase_string[phase])
216 
221 enum mps_operation {
222  MPS_OPERATION_CLUSTER_ANALYSIS,
223  MPS_OPERATION_ABERTH_FP_ITERATIONS,
224  MPS_OPERATION_ABERTH_DPE_ITERATIONS,
225  MPS_OPERATION_ABERTH_MP_ITERATIONS,
226  MPS_OPERATION_REGENERATION,
227  MPS_OPERATION_STARTING_POINTS_FP,
228  MPS_OPERATION_STARTING_POINTS_DPE,
229  MPS_OPERATION_STARTING_POINTS_MP,
230  MPS_OPERATION_SHIFT,
231  MPS_OPERATION_REFINEMENT
232 };
233 static const mps_string mps_operation_string [] = {
234  "Cluster Analysis", "Aberth floating point iterations", "Aberth DPE iterations",
235  "Aberth multiprecision iterations", "Regeneration", "Starting point computation in floating point",
236  "Starting point computatino in DPE", "Starting point computation in multiprecision",
237  "Shift of the polynomial", "Refinement of the approximation"
238 };
239 #define MPS_OPERATION_TO_STRING(operation) (mps_operation_string[operation])
240 
244 enum mps_root_status {
245  MPS_ROOT_STATUS_NEW_CLUSTERED,
246  MPS_ROOT_STATUS_CLUSTERED,
247  MPS_ROOT_STATUS_ISOLATED,
248  MPS_ROOT_STATUS_APPROXIMATED,
249  MPS_ROOT_STATUS_APPROXIMATED_IN_CLUSTER,
250  MPS_ROOT_STATUS_NOT_FLOAT,
251  MPS_ROOT_STATUS_NOT_DPE,
252  MPS_ROOT_STATUS_MULTIPLE
253 };
254 
255 /* Macros to check root status */
256 static const mps_boolean mps_table_of_approximated_roots [] = { false, false, false, true, true, false, false, false };
257 static const mps_boolean mps_table_of_computed_roots [] = { false, false, true, true, true, false, false, false };
258 static const mps_boolean mps_table_of_improvable_roots [] = { false, false, true, true, false, false, false, false };
259 #define MPS_ROOT_STATUS_IS_APPROXIMATED(status) (mps_table_of_approximated_roots[status])
260 #define MPS_ROOT_STATUS_IS_COMPUTED(status) (mps_table_of_computed_roots[status])
261 #define MPS_ROOT_STATUS_IS_IMPROVABLE(status) (mps_table_of_improvable_roots[status])
262 
263 /* Cast of root_status to string */
264 static const mps_string mps_root_status_string[] = {
265  "Clustered (pinned)",
266  "Clustered",
267  "Isolated",
268  "Approximated",
269  "Approximated in a cluster",
270  "Not representable as floating point",
271  "Not representable as DPE",
272  "Multiple root"
273 };
274 #define MPS_ROOT_STATUS_TO_STRING(status) (mps_root_status_string[status])
275 
280 enum mps_root_attrs {
281  MPS_ROOT_ATTRS_NONE,
282  MPS_ROOT_ATTRS_REAL,
283  MPS_ROOT_ATTRS_NOT_REAL,
284  MPS_ROOT_ATTRS_IMAG,
285  MPS_ROOT_ATTRS_NOT_IMAG,
286  MPS_ROOT_ATTRS_NOT_REAL_AND_IMAG
287 };
288 
289 /* Cast of root_attrs to string */
290 static const mps_string mps_root_attrs_string [] = {
291  "None",
292  "Real",
293  "Not real",
294  "Imaginary",
295  "Not imaginary",
296  "Not Real nor imaginary"
297 };
298 #define MPS_ROOT_ATTRS_TO_STRING(attrs) (mps_root_attrs_string[attrs])
299 
304 enum mps_root_inclusion {
305  MPS_ROOT_INCLUSION_UNKNOWN,
306  MPS_ROOT_INCLUSION_IN,
307  MPS_ROOT_INCLUSION_OUT
308 };
309 
310 /* Cast of mps_root_inclusion to string */
311 static const mps_string mps_root_inclusion_string [] = {
312  "Unknown",
313  "In",
314  "Out",
315 };
316 #define MPS_ROOT_INCLUSION_TO_STRING(inclusion) (mps_root_inclusion_string[inclusion])
317 
322 enum mps_algorithm {
326  MPS_ALGORITHM_STANDARD_MPSOLVE,
327 
331  MPS_ALGORITHM_SECULAR_GA
332 };
333 
339 enum mps_option_key {
340  /* Flag for UNDEFINED Options */
341  MPS_FLAG_UNDEFINED,
342 
343  /* Key without values associated */
344  MPS_FLAG_INTEGER,
345  MPS_FLAG_REAL,
346  MPS_FLAG_COMPLEX,
347  MPS_FLAG_RATIONAL,
348  MPS_FLAG_FP,
349 
350  MPS_FLAG_SECULAR,
351  MPS_FLAG_MONOMIAL,
352 
353  MPS_FLAG_DENSE,
354  MPS_FLAG_SPARSE,
355 
356  /* Key with a value */
357  MPS_KEY_DEGREE,
358  MPS_KEY_PRECISION,
359 
360  /* Key introduced in MPSolve 3.1 */
361  MPS_FLAG_CHEBYSHEV
362 };
363 
371 enum mps_structure {
372  MPS_STRUCTURE_REAL_INTEGER,
373  MPS_STRUCTURE_REAL_RATIONAL,
374  MPS_STRUCTURE_REAL_FP,
375  MPS_STRUCTURE_REAL_BIGFLOAT,
376  MPS_STRUCTURE_COMPLEX_INTEGER,
377  MPS_STRUCTURE_COMPLEX_RATIONAL,
378  MPS_STRUCTURE_COMPLEX_FP,
379  MPS_STRUCTURE_COMPLEX_BIGFLOAT,
380  MPS_STRUCTURE_UNKNOWN
381 };
382 
389 enum mps_density {
390  MPS_DENSITY_DENSE,
391  MPS_DENSITY_SPARSE,
392  MPS_DENSITY_USER,
393 };
394 
398 enum mps_output_format {
399  MPS_OUTPUT_FORMAT_COMPACT,
400  MPS_OUTPUT_FORMAT_GNUPLOT,
401  MPS_OUTPUT_FORMAT_GNUPLOT_FULL,
402  MPS_OUTPUT_FORMAT_BARE,
403  MPS_OUTPUT_FORMAT_FULL,
404  MPS_OUTPUT_FORMAT_VERBOSE
405 };
406 
410 enum mps_output_goal {
411  MPS_OUTPUT_GOAL_ISOLATE,
412  MPS_OUTPUT_GOAL_APPROXIMATE,
413  MPS_OUTPUT_GOAL_COUNT
414 };
415 
419 enum mps_search_set {
423  MPS_SEARCH_SET_COMPLEX_PLANE,
424 
428  MPS_SEARCH_SET_POSITIVE_REAL_PART,
429 
433  MPS_SEARCH_SET_NEGATIVE_REAL_PART,
434 
438  MPS_SEARCH_SET_POSITIVE_IMAG_PART,
439 
443  MPS_SEARCH_SET_NEGATIVE_IMAG_PART,
444 
449  MPS_SEARCH_SET_UNITARY_DISC,
450 
455  MPS_SEARCH_SET_UNITARY_DISC_COMPL,
456 
460  MPS_SEARCH_SET_REAL,
461 
465  MPS_SEARCH_SET_IMAG,
466 
470  MPS_SEARCH_SET_CUSTOM
471 };
472 
476 enum mps_representation {
477  MPS_REPRESENTATION_SECULAR,
478  MPS_REPRESENTATION_MONOMIAL,
479  MPS_REPRESENTATION_CHEBYSHEV
480 };
481 
485 enum mps_starting_strategy {
486  MPS_STARTING_STRATEGY_DEFAULT,
487  MPS_STARTING_STRATEGY_RECURSIVE,
488  MPS_STARTING_STRATEGY_FILE
489 };
490 
491 #endif /* endif MPS_TYPES_H_ */
mps_cluster_item
Cluster held in a mps_clusterization.
Definition: cluster.h:72
mps_list_element
Definition: list.h:25
mps_monomial_poly
Data regarding a polynomial represented in the monomial base.
Definition: monomial-poly.h:44
mps_root
This struct represent a root inside of a mps_cluster.
Definition: cluster.h:30
mps_opt
Struct holding the options passed on the command line.
Definition: options.h:97
mps_command_line_option
This struct holds a configuration for a command line option. This is a step towards a more flexible i...
Definition: options.h:28
mps_context
this struct holds the state of the mps computation
Definition: context.h:55
mps_input_option
This struct holds a key and the value associated with it. It's used for options that require a value ...
Definition: options.h:110
mps_thread_worker_data
Data packed to be passed to a new thread that will perform floating point, dpe or multiprecision iter...
Definition: threading.h:116
mps_thread_job
A new job for mps_thread_fsolve(), mps_thread_dsolve() or mps_thread_msolve().
Definition: threading.h:44
mt-types.h
Implementation of some thread-safe types that can be easily used with the macro MPS_LOCK() and MPS_UN...
mps_regeneration_driver
This type represent an abstract implementation of a driver for the regeneration step of the main algo...
Definition: regeneration-driver.h:31
mps_polynomial
Struct that represents an abstract polynomial. All the other real polynomial implementations (such as...
Definition: polynomial.h:111
mps_command_line_option_configuration
Configuration for a command line parser.
Definition: options.h:65
mps_monomial_matrix_poly
This is the struct that holds all the data of the matrix polynomial.
Definition: monomial-matrix-poly.h:39
mps_output_configuration
Configuration for the output.
Definition: options.h:174
mps_cluster
A cluster of mps_roots.
Definition: cluster.h:51
mps_input_configuration
Configuration for an input stream; this struct contains the information on how the input stream shoul...
Definition: options.h:151
mps_approximation
Definition: approximation.h:24
mps_thread_pool_queue_item
An item that can be inserted and/or extracted from a mps_thread_pool_queue.
Definition: threading.h:265
mps_thread
A thread that is part of a thread pool.
Definition: threading.h:198
mps_secular_equation
Secular equation data.
Definition: secular-equation.h:63
mps_clusterization
A list of mps_cluster.
Definition: cluster.h:100
mps_input_buffer
Buffer used to parse input files in MPSolve. It can read a stream line by line.
Definition: input-buffer.h:33
mps_thread_pool
A thread pool that contains a set of mps_thread and allow to manage them as a set of worker.
Definition: threading.h:303
mps_secular_iteration_data
This is a struct that represent an iteration on a root. It contains information that could be useful ...
Definition: secular-equation.h:189
mps_thread_pool_queue
A queue of work items that thread can consume.
Definition: threading.h:285
mps_list
Definition: list.h:50
mps_thread_job_queue
Struct holding a job queue.
Definition: threading.h:76