FORM v5.0.0-35-g6318119
flintinterface.h
Go to the documentation of this file.
1#pragma once
6/* #[ License : */
7/*
8 * Copyright (C) 1984-2026 J.A.M. Vermaseren
9 * When using this file you are requested to refer to the publication
10 * J.A.M.Vermaseren "New features of FORM" math-ph/0010025
11 * This is considered a matter of courtesy as the development was paid
12 * for by FOM the Dutch physics granting agency and we would like to
13 * be able to track its scientific use to convince FOM of its value
14 * for the community.
15 *
16 * This file is part of FORM.
17 *
18 * FORM is free software: you can redistribute it and/or modify it under the
19 * terms of the GNU General Public License as published by the Free Software
20 * Foundation, either version 3 of the License, or (at your option) any later
21 * version.
22 *
23 * FORM is distributed in the hope that it will be useful, but WITHOUT ANY
24 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
26 * details.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with FORM. If not, see <http://www.gnu.org/licenses/>.
30 */
31/* #] License : */
32
33extern "C" {
34#include "form3.h"
35}
36
37#if defined(WINDOWS)
38// flint.h defines WORD(xx), which conflicts with the one defined in form3.h.
39#undef WORD
40#endif
41
42#include <flint/flint.h>
43#if __FLINT_RELEASE >= 30000
44#include <flint/gr.h>
45#endif
46#include <flint/fmpz.h>
47#include <flint/fmpz_mpoly.h>
48#include <flint/fmpz_mpoly_factor.h>
49#include <flint/fmpz_poly.h>
50#include <flint/fmpz_poly_factor.h>
51
52#if defined(WINDOWS)
53// Redefine WORD here to match form3.h.
54#undef WORD
55#define WORD FORM_WORD
56#endif
57
58#include <cassert>
59#include <cstdint>
60#include <iostream>
61#include <map>
62#include <vector>
63
64
65// The bits of std that are needed:
66using std::cout;
67using std::endl;
68using std::map;
69using std::swap;
70using std::string;
71using std::vector;
72
73
74namespace flint {
75
76 typedef std::map<uint32_t,uint32_t> var_map_t;
77
78 // Small wrappers around the flint structs to enable RAII init and clear. "d" represents the
79 // data, and this member will be passed to flint functions.
80 class fmpz {
81 public:
82 fmpz_t d;
83 fmpz() { fmpz_init(d); }
84 ~fmpz() { fmpz_clear(d); }
85 void print(const string& text) { cout << text; fmpz_print(d); cout << endl; }
86 };
87 class poly {
88 public:
89 fmpz_poly_t d;
90 poly() { fmpz_poly_init(d); }
91 ~poly() { fmpz_poly_clear(d); }
92 void print(const string& text) {
93 cout << text; fmpz_poly_print_pretty(d, "x"); cout << endl;
94 }
95 };
97 public:
98 fmpz_poly_factor_t d;
99 poly_factor() { fmpz_poly_factor_init(d); }
100 ~poly_factor() { fmpz_poly_factor_clear(d); }
101 };
102 class mpoly {
103 private:
104 fmpz_mpoly_ctx_struct *ctx; // We need to keep a copy of the context pointer for clearing.
105 public:
106 fmpz_mpoly_t d;
107 explicit mpoly(fmpz_mpoly_ctx_struct *ctx_in) : ctx(ctx_in) { fmpz_mpoly_init(d, ctx); }
108 ~mpoly() { fmpz_mpoly_clear(d, ctx); }
109 void print(const string& text) {
110 cout << text;
111 fmpz_mpoly_print_pretty(d, 0, ctx);
112 cout << endl;
113 }
114 };
116 private:
117 fmpz_mpoly_ctx_struct *ctx; // We need to keep a copy of the context pointer for clearing.
118 public:
119 fmpz_mpoly_factor_t d;
120 explicit mpoly_factor(fmpz_mpoly_ctx_struct *ctx_in) : ctx(ctx_in) {
121 fmpz_mpoly_factor_init(d, ctx);
122 }
123 ~mpoly_factor() { fmpz_mpoly_factor_clear(d, ctx); }
124 };
125 class mpoly_ctx {
126 public:
127 fmpz_mpoly_ctx_t d;
128 explicit mpoly_ctx(int64_t nvars) { fmpz_mpoly_ctx_init(d, nvars, ORD_LEX); }
129 ~mpoly_ctx() { fmpz_mpoly_ctx_clear(d); }
130 };
131
132 void cleanup(void);
133 void cleanup_master(void);
134
135 WORD* divmod_mpoly(PHEAD const WORD *, const WORD *, const bool, const WORD, const var_map_t &);
136 WORD* divmod_poly(PHEAD const WORD *, const WORD *, const bool, const WORD, const var_map_t &);
137
138 WORD* factorize_mpoly(PHEAD const WORD *, WORD *, const bool, const bool, const var_map_t &);
139 WORD* factorize_poly(PHEAD const WORD *, WORD *, const bool, const bool, const var_map_t &);
140
141 void form_sort(PHEAD WORD *);
142
143 uint64_t from_argument_mpoly(fmpz_mpoly_t, fmpz_mpoly_t, const WORD *, const bool,
144 const var_map_t &, const fmpz_mpoly_ctx_t);
145 uint64_t from_argument_poly(fmpz_poly_t, fmpz_poly_t, const WORD *, const bool);
146
147 WORD fmpz_get_form(fmpz_t, WORD *);
148 void fmpz_set_form(fmpz_t, UWORD *, WORD);
149
150 WORD* gcd_mpoly(PHEAD const WORD *, const WORD *, const WORD, const var_map_t &);
151 WORD* gcd_poly(PHEAD const WORD *, const WORD *, const WORD, const var_map_t &);
152
153 var_map_t get_variables(const vector <WORD *> &, const bool, const bool);
154
155 WORD* inverse_poly(PHEAD const WORD *, const WORD *, const var_map_t &);
156
157 WORD* mul_mpoly(PHEAD const WORD *, const WORD *, const var_map_t &);
158 WORD* mul_poly(PHEAD const WORD *, const WORD *, const var_map_t &);
159
160 void ratfun_add_mpoly(PHEAD const WORD *, const WORD *, WORD *, const var_map_t &);
161 void ratfun_add_poly(PHEAD const WORD *, const WORD *, WORD *, const var_map_t &);
162
163 void ratfun_normalize_mpoly(PHEAD WORD *, const var_map_t &);
164 void ratfun_normalize_poly(PHEAD WORD *, const var_map_t &);
165
166 void ratfun_read_mpoly(const WORD *, fmpz_mpoly_t, fmpz_mpoly_t, const var_map_t &,
167 fmpz_mpoly_ctx_t);
168 void ratfun_read_poly(const WORD *, fmpz_poly_t, fmpz_poly_t);
169
170 uint64_t to_argument_mpoly(PHEAD WORD *, const bool, const bool, const bool, const uint64_t,
171 const fmpz_mpoly_t, const var_map_t &, const fmpz_mpoly_ctx_t);
172 uint64_t to_argument_mpoly(PHEAD WORD *, const bool, const bool, const bool, const uint64_t,
173 const fmpz_mpoly_t, const var_map_t &, const fmpz_mpoly_ctx_t, const fmpz_t);
174 uint64_t to_argument_poly(PHEAD WORD *, const bool, const bool, const bool, const uint64_t,
175 const fmpz_poly_t, const var_map_t &);
176 uint64_t to_argument_poly(PHEAD WORD *, const bool, const bool, const bool, const uint64_t,
177 const fmpz_poly_t, const var_map_t &, const fmpz_t);
178
179
180 namespace util {
181
182 void simplify_fmpz(fmpz_t, fmpz_t, fmpz_t);
183 void simplify_fmpz_poly(fmpz_poly_t, fmpz_poly_t, fmpz_poly_t);
184
185 void fix_sign_fmpz_mpoly_ratfun(fmpz_mpoly_t, fmpz_mpoly_t, const fmpz_mpoly_ctx_t);
186 void fix_sign_fmpz_poly_ratfun(fmpz_poly_t, fmpz_poly_t);
187
188 }
189
190}