HepLib
Loading...
Searching...
No Matches
BASIC.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ginac/ginac.h>
9#include <ginac/parser.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <stdio.h>
13#include <chrono>
14#include <fstream>
15#include <tuple>
16#include <list>
17#include <omp.h>
18#include <sys/wait.h>
19#include <sys/stat.h>
20
21#define DEFAULT_CTOR(classname) \
22classname::classname() { setflag(status_flags::evaluated | status_flags::expanded); }
23
24#define IMPLEMENT_HAS(classname) \
25bool classname::has(const ex &e) { \
26 for(const_preorder_iterator i = e.preorder_begin(); i != e.preorder_end(); ++i) if(is_a<classname>(*i)) return true; \
27 return false; \
28}
29
30#define IMPLEMENT_ALL(classname) \
31lst classname::all(const ex &e) { \
32 lst ret;\
33 for(const_preorder_iterator i = e.preorder_begin(); i != e.preorder_end(); ++i) if(is_a<classname>(*i)) ret.append(*i); \
34 ret.sort(); \
35 ret.unique(); \
36 return ret; \
37}
38
42namespace HepLib {
43
44 using namespace std;
45 using namespace GiNaC;
46
47 typedef std::initializer_list<ex> init_list;
48 extern string Version;
49 extern unsigned nopat;
50
51 inline ex subs(const ex & e, init_list sl) {
52 return e.subs(lst(sl));
53 }
54
55 inline bool has_any(ex expr, lst ps) {
56 for(auto pi : ps) if(expr.has(pi)) return true;
57 return false;
58 }
59 inline bool has_all(ex expr, lst ps) {
60 for(auto pi : ps) if(!expr.has(pi)) return false;
61 return true;
62 }
63
64 inline bool is_equal_any(ex expr, lst ps) {
65 for(auto pi : ps) if(expr.is_equal(pi)) return true;
66 return false;
67 }
68
69 inline bool match_any(ex expr, lst ps) {
70 for(auto pi : ps) if(expr.match(pi)) return true;
71 return false;
72 }
73 inline bool match_all(ex expr, lst ps) {
74 for(auto pi : ps) if(!expr.match(pi)) return false;
75 return true;
76 }
77
78 // Terminal Color
79 #define RESET "\033[0m"
80 #define BLACK "\033[30m"
81 #define RED "\033[31m"
82 #define GREEN "\033[32m"
83 #define YELLOW "\033[33m"
84 #define BLUE "\033[34m"
85 #define MAGENTA "\033[35m"
86 #define CYAN "\033[36m"
87 #define WHITE "\033[37m"
88 #define BOLDBLACK "\033[1m\033[30m"
89 #define BOLDRED "\033[1m\033[31m"
90 #define BOLDGREEN "\033[1m\033[32m"
91 #define BOLDYELLOW "\033[1m\033[33m"
92 #define BOLDBLUE "\033[1m\033[34m"
93 #define BOLDMAGENTA "\033[1m\033[35m"
94 #define BOLDCYAN "\033[1m\033[36m"
95 #define BOLDWHITE "\033[1m\033[37m"
96
97 extern const int o_none;
98 extern const int o_normal;
99 extern const int o_fermat;
100 extern const int o_fermatfD;
101 extern const int o_fermatN;
102 extern const int o_form;
103 extern const int o_flint;
104 extern const int o_flint_ccf;
105 extern const int o_flintf;
106 extern const int o_flintf_ccf;
107 extern const int o_flintfD;
108 extern const int o_flintfD_ccf;
109 extern const int o_normal_fermat;
110 extern const int o_normal_form;
111 extern const int o_fermat_form;
112
116 class Symbol : public symbol {
117 //GINAC_DECLARE_REGISTERED_CLASS(Symbol, symbol)
118 private:
119 static GiNaC::registered_class_info reg_info;
120 public:
121 static GiNaC::registered_class_info &get_class_info_static();
122 class visitor {
123 public:
124 virtual void visit(const Symbol &) = 0; // classname
125 virtual ~visitor();
126 };
127 template<class B, typename... Args> friend B & dynallocate(Args &&... args);
128 typedef symbol inherited; // supername
129 Symbol(); // classname
130 Symbol * duplicate() const override; // classname
131 void accept(GiNaC::visitor & v) const override;
132 const GiNaC::registered_class_info &get_class_info() const override;
133 GiNaC::registered_class_info &get_class_info() override;
134 const char *class_name() const override;
135 protected:
136 int compare_same_type(const GiNaC::basic & other) const override;
137 // GINAC_DECLARE_REGISTERED_CLASS END
138
139 public:
140 explicit Symbol(const string &s);
141 void archive(archive_node & n) const override;
142 void read_archive(const archive_node& n) override;
143
144 //bool info(unsigned inf) const override;
145 ex eval() const override; // for performance reasons
146 ex evalf() const override; // for performance reasons
147 ex series(const relational & s, int order, unsigned options = 0) const override;
148 ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
149 //ex normal(exmap & repl, exmap & rev_lookup, lst & modifier) const override;
150 //ex to_rational(exmap & repl) const override;
151 //ex to_polynomial(exmap & repl) const override;
152 //bool is_polynomial(const ex & var) const override;
153
154 ex conjugate() const override;
155 ex real_part() const override;
156 ex imag_part() const override;
157 void set_name(string n);
158
159 unsigned get_domain() const override { return domain::positive; }
160
161 static bool has(const ex &e);
162 static lst all(const ex &e);
163 static std::map<std::string, ex> Table;
164
165 void set(const ex & v) const;
166 void unset() const;
167
168 unsigned get_serial() { return serial; }
169
170 static exmap vmap;
171 static void set(const Symbol & s, const ex & v);
172 static void set(const string & str, const ex & v);
173 static void unset(const Symbol &s);
174 static void unset(const string &str);
175 static void unset_all();
176 static ex set_all(const ex & expr);
177 protected:
178 unsigned calchash() const override;
179 ex derivative(const symbol & s) const override;
180 bool is_equal_same_type(const basic & other) const override;
181 };
182
186 class iSymbol : public symbol {
187 //GINAC_DECLARE_REGISTERED_CLASS(iSymbol, symbol)
188 private:
189 static GiNaC::registered_class_info reg_info;
190 public:
191 static GiNaC::registered_class_info &get_class_info_static();
192 class visitor {
193 public:
194 virtual void visit(const iSymbol &) = 0; // classname
195 virtual ~visitor();
196 };
197 template<class B, typename... Args> friend B & dynallocate(Args &&... args);
198 typedef symbol inherited; // supername
199 iSymbol(); // classname
200 iSymbol * duplicate() const override; // classname
201 void accept(GiNaC::visitor & v) const override;
202 const GiNaC::registered_class_info &get_class_info() const override;
203 GiNaC::registered_class_info &get_class_info() override;
204 const char *class_name() const override;
205 protected:
206 int compare_same_type(const GiNaC::basic & other) const override;
207 // GINAC_DECLARE_REGISTERED_CLASS END
208
209 public:
210 iSymbol(const string &s);
211 void archive(archive_node & n) const override;
212 void read_archive(const archive_node& n) override;
213
214 unsigned get_domain() const override { return domain::complex; }
215
216 //bool info(unsigned inf) const override;
217 ex eval() const override; // for performance reasons
218 ex evalf() const override; // for performance reasons
219 ex series(const relational & s, int order, unsigned options = 0) const override;
220 ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons
221 //ex normal(exmap & repl, exmap & rev_lookup, lst & modifier) const override;
222 //ex to_rational(exmap & repl) const override;
223 //ex to_polynomial(exmap & repl) const override;
224 //bool is_polynomial(const ex & var) const override;
225
226 ex conjugate() const override;
227 ex real_part() const override;
228 ex imag_part() const override;
229 void set_name(string n);
230
231 static bool has(const ex &e);
232 static lst all(const ex &e);
233 static std::map<std::string, ex> Table;
234
235 protected:
236 unsigned calchash() const override;
237 ex derivative(const symbol & s) const override;
238 bool is_equal_same_type(const basic & other) const override;
239 };
240
241
245 class Error : public exception {
246 public:
247 string msg;
248 const char * what() const throw ();
249 Error(string _msg);
250 };
251
252 vector<std::string> split(const string& s, char delimiter);
253
254
258 class lstHelper {
259 public:
260 template <typename F> static void map_inplace(lst &m, F f);
261 template <typename F> static lst map(const lst &m, F f);
262 static ex sum(lst m);
263 };
264
265 template <typename F>
266 void lstHelper::map_inplace(lst &m, F f) {
267 for (unsigned i = 0; i < m.nops(); i++) {
268 m[i] = f(m.op(i));
269 }
270 }
271
272 template <typename F>
273 lst lstHelper::map(const lst &m, F f) {
274 lst r = m;
275 for (unsigned i = 0; i < m.nops(); i++) {
276 r[i] = f(m.op(i));
277 }
278 return r;
279 }
280
281 /*-----------------------------------------------------*/
282 // Global Functions
283 /*-----------------------------------------------------*/
284 string now(bool use_date = true);
285 lst gather_symbols(const ex & e);
286 lst gather_symbols(const exvector & ve);
287
288 inline bool file_remove(string fn) {
289 return remove(fn.c_str())==0;
290 }
291
292 inline bool file_exists(string fn) {
293 return (access(fn.c_str(),F_OK)!=-1);
294 }
295
296 inline bool key_exists(const exmap &map, const ex & key) {
297 return (map.find(key)!=map.end());
298 }
299
300 inline bool dir_exists(string dir) {
301 struct stat buffer;
302 return (stat(dir.c_str(), &buffer)==0);
303 }
304
305 /*-----------------------------------------------------*/
306 // vector : GiNaC_Parallel
307 /*-----------------------------------------------------*/
308 extern bool In_GiNaC_Parallel;
309 extern int GiNaC_Parallel_Level;
310 extern int GiNaC_Parallel_Process;
311 extern map<string, int> GiNaC_Parallel_Verb;
312 extern map<string, int> GiNaC_Parallel_NP;
313 extern int GiNaC_Parallel_Batch;
314 extern map<string,int> GiNaC_Parallel_NB;
315 extern map<string,bool> GiNaC_Parallel_RM;
316 extern map<string,bool> GiNaC_Parallel_ReWR;
317 extern map<string,string> GiNaC_Parallel_PRE;
318 exvector GiNaC_Parallel(int ntotal, std::function<ex(int)> f, const string & key = "");
319
320 /*-----------------------------------------------------*/
321 // Helpers
322 /*-----------------------------------------------------*/
323 string RunOS(const string & cmd);
324 void garRead(const string &garfn, map<string, ex> &resMap);
325 ex garRead(const string &garfn, const char* key);
326 ex garRead(const string &garfn);
327 void garWrite(const string &garfn, const map<string, ex> &resMap);
328 inline void garWrite(const map<string, ex> &resMap, const string &garfn) { garWrite(garfn,resMap); }
329 void garWrite(const string &garfn, const ex & res);
330 inline void garWrite(const ex & res, const string &garfn) { garWrite(garfn,res); }
331
332 ex str2ex(const string &expr, symtab stab);
333 ex str2ex(const string &expr);
334 lst str2lst(const string &expr, symtab stab);
335 lst str2lst(const string &expr);
336 matrix lst2mat(const lst & ls);
337 string file2str(string filename);
338 void str2file(const string & ostr, string filename);
339 void str2file(char * buff, FILE* f);
340 vector<string> file2strvec(string filename, bool skip_empty=false);
341 ex file2ex(string filename);
342 ex file2ex(string filename, symtab st);
343 int ex2int(ex);
344 void ex2file(const ex &, string filename);
345 void ex2file(string filename, const ex &);
346 string ex2str(const ex &expr);
347 string ex2str(const exvector &expr);
348 string ex2str(const exmap &expr);
349 string ex2str(const exset &expr);
350 inline string in2str(int i) { return to_string(i); }
351 ex q2ex(__float128);
352 __float128 ex2q(ex);
353 lst vec2lst(const exvector & ev);
354 exvector lst2vec(const lst & alst);
355 lst add2lst(const ex & expr);
356 lst mul2lst(const ex & expr);
357 lst xlst(int ei);
358 lst xlst(int bi, int ei);
359 int CpuCores();
360
361 void let_op_append(ex & ex_in, const ex item);
362 void let_op_prepend(ex & ex_in, const ex item);
363 void let_op_remove_last(ex & ex_in);
364 void let_op_remove_first(ex & ex_in);
365
366 void let_op_append(ex & ex_in, int index, const ex item);
367 void let_op_prepend(ex & ex_in, int index, const ex item);
368 void let_op_remove_last(ex & ex_in, int index);
369 void let_op_remove_first(ex & ex_in, int index);
370 void let_op_append(lst & ex_in, int index, const ex item);
371 void let_op_prepend(lst & ex_in, int index, const ex item);
372 void let_op_remove_last(lst & ex_in, int index);
373 void let_op_remove_first(lst & ex_in, int index);
374
375 void let_op_append(ex & ex_in, int index1, int index2, const ex item);
376 void let_op_prepend(ex & ex_in, int index1, int index2, const ex item);
377 void let_op_remove_last(ex & ex_in, int index1, int index2);
378 void let_op_remove_first(ex & ex_in, int index1, int index2);
379 void let_op_append(lst & ex_in, int index1, int index2, const ex item);
380 void let_op_prepend(lst & ex_in, int index1, int index2, const ex item);
381 void let_op_remove_last(lst & ex_in, int index1, int index2);
382 void let_op_remove_first(lst & ex_in, int index1, int index2);
383
384 void let_op(ex &ex_in, int index1, int index2, const ex item);
385 void let_op(lst &ex_in, int index1, int index2, const ex item);
386 void let_op(ex &ex_in, int index1, int index2, int index3, const ex item);
387 void let_op(lst &ex_in, int index1, int index2, int index3, const ex item);
388
389 ex get_op(const ex ex_in, int index1, int index2);
390 ex get_op(const lst ex_in, int index1, int index2);
391 ex get_op(const ex ex_in, int index1, int index2, int index3);
392 ex get_op(const lst ex_in, int index1, int index2, int index3);
393
394 /*-----------------------------------------------------*/
395 // Series at s=0 similar to Mathematica
396 /*-----------------------------------------------------*/
397 ex series_ex(ex const & expr, const symbol &s, int sn);
398 ex series_ex(ex const & expr, const ex &s, int sn);
399
400 ex expand_ex(const ex &expr, std::function<bool(const ex &)>);
401
402 inline ex expand_ex(const ex &expr) {
403 return expand_ex(expr, [](const ex & e)->bool{ return true; });
404 }
405
406 inline ex expand_ex(ex const &expr, lst const &pats) {
407 return expand_ex(expr, [pats](const ex & e)->bool {
408 for(auto pat : pats) { if(e.has(pat)) return true; }
409 return false;
410 });
411 }
412
413 inline ex expand_ex(ex const &expr, ex const &pat) {
414 return expand_ex(expr, [pat](const ex & e)->bool { return e.has(pat); });
415 }
416
417 ex collect_ex(const ex &expr, std::function<bool(const ex &)>, int opt=o_none);
418
419 inline ex collect_ex(const ex &expr, init_list const &pats, int opt=o_none) {
420 return collect_ex(expr, [pats](const ex & e)->bool {
421 for(auto pat : pats) { if(e.has(pat)) return true; }
422 return false;
423 }, opt);
424 }
425
426 inline ex collect_ex(const ex &expr, lst const &pats, int opt=o_none) {
427 return collect_ex(expr, [pats](const ex & e)->bool {
428 for(auto pat : pats) { if(e.has(pat)) return true; }
429 return false;
430 }, opt);
431 }
432
433 inline ex collect_ex(const ex &expr, ex const &pat, int opt=o_none) {
434 return collect_ex(expr, [pat](const ex & e)->bool { return e.has(pat); }, opt);
435 }
436
437 lst collect_lst(const ex &expr, std::function<bool(const ex &)>, int opt=o_none);
438
439 inline lst collect_lst(const ex &expr, init_list const &pats, int opt=o_none) {
440 return collect_lst(expr, [pats](const ex & e)->bool {
441 for(auto pat : pats) { if(e.has(pat)) return true; }
442 return false;
443 }, opt);
444 }
445
446 inline lst collect_lst(const ex &expr, lst const &pats, int opt=o_none) {
447 return collect_lst(expr, [pats](const ex & e)->bool {
448 for(auto pat : pats) { if(e.has(pat)) return true; }
449 return false;
450 }, opt);
451 }
452
453 inline lst collect_lst(const ex &expr, ex const &pat, int opt=o_none) {
454 return collect_lst(expr, [pat](const ex & e)->bool { return e.has(pat); }, opt);
455 }
456
457 ex diff_ex(ex const expr, ex const xp, unsigned nth=1, bool expand=false);
458
459 extern bool using_cache;
460 extern long long cache_limit;
461 extern int fermat_using_array;
462 ex fermat_eval(const ex & expr);
463 ex numer_denom_fermat(const ex & expr, bool dfactor=false);
464 ex numer_fermat(const ex & expr);
465 inline ex fermat_numer_denom(const ex & expr, bool dfactor=false) { return numer_denom_fermat(expr,dfactor); }
466
467 extern map<ex,long long,ex_is_less> fermat_weight;
468 ex normal_fermat(const ex & expr, bool dfactor=false);
469 inline ex fermat_normal(const ex & expr, bool dfactor=false) { return normal_fermat(expr,dfactor); }
470
471 ex normal_flint(const ex & expr, int opt=o_flint);
472 ex factor_flint(const ex & e, bool nd=true);
473
474 ex form_eval(const ex & expr);
475 ex factor_form(const ex & expr, bool nd=true);
476 inline ex form_factor(const ex & expr, bool nd=true) { return factor_form(expr,nd); }
477
478 ex exfactor(const ex & expr, int opt = o_flint);
479 ex exnormal(const ex & expr, int opt = o_flint);
480 ex exnd(const ex & expr, int opt = 1);
481
482 ex collect_factors(const ex & expr);
483
484 /*-----------------------------------------------------*/
485 // EvalF/D/Q/MP
486 /*-----------------------------------------------------*/
487 ex EvalF(ex);
488 ex EvalL(ex);
489 ex EvalQ(ex);
490 ex EvalMP(ex);
491 extern int NNDigits;
492 ex NN(ex expr,int digits=NNDigits);
493
494 /*-----------------------------------------------------*/
495 // xPositive
496 /*-----------------------------------------------------*/
497 bool xPositive(ex const expr);
498 int xSign(ex const expr);
499
500 /*-----------------------------------------------------*/
501 // Global object wildcard
502 /*-----------------------------------------------------*/
503 extern ex w, w0, w1, w2, w3, w4, w5, w6, w7, w8, w9;
504 extern string InstallPrefix;
505 extern string INC_FLAGS;
506 extern string LIB_FLAGS;
507 extern const iSymbol iEpsilon;
508 extern const ex iEpsilonN;
509 extern int Verbose;
510 extern string PRE;
511 extern bool Debug;
512
513 /*-----------------------------------------------------*/
514 // Global Colors
515 /*-----------------------------------------------------*/
516 extern const char* ErrColor;
517 extern const char* WarnColor;
518 extern const char* Color_HighLight;
519
520 /*-----------------------------------------------------*/
521 // Customized GiNaC Function
522 /*-----------------------------------------------------*/
523 DECLARE_FUNCTION_1P(x)
524 DECLARE_FUNCTION_1P(y)
525 DECLARE_FUNCTION_1P(z)
526
527 #ifndef DOXYGEN_SKIP
528
529 class F1_SERIAL { public: static unsigned serial; };
530 template<typename T1>
531 inline GiNaC::function F(const T1 & p1) {
532 return GiNaC::function(F1_SERIAL::serial, ex(p1));
533 }
534
535 class F2_SERIAL { public: static unsigned serial; };
536 template<typename T1, typename T2>
537 inline GiNaC::function F(const T1 & p1, const T2 & p2) {
538 return GiNaC::function(F2_SERIAL::serial, ex(p1), ex(p2));
539 }
540
541 class WF1_SERIAL { public: static unsigned serial; };
542 template<typename T1>
543 inline GiNaC::function WF(const T1 & p1) {
544 return GiNaC::function(WF1_SERIAL::serial, ex(p1));
545 }
546
547 class WF2_SERIAL { public: static unsigned serial; };
548 template<typename T1, typename T2>
549 inline GiNaC::function WF(const T1 & p1, const T2 & p2) {
550 return GiNaC::function(WF2_SERIAL::serial, ex(p1), ex(p2));
551 }
552
553 class WF3_SERIAL { public: static unsigned serial; };
554 template<typename T1, typename T2, typename T3>
555 inline GiNaC::function WF(const T1 & p1, const T2 & p2, const T3 & p3) {
556 return GiNaC::function(WF3_SERIAL::serial, ex(p1), ex(p2), ex(p3));
557 }
558
559 class WF4_SERIAL { public: static unsigned serial; };
560 template<typename T1, typename T2, typename T3, typename T4>
561 inline GiNaC::function WF(const T1 & p1, const T2 & p2, const T3 & p3, const T4 & p4) {
562 return GiNaC::function(WF4_SERIAL::serial, ex(p1), ex(p2), ex(p3), ex(p4));
563 }
564
565 class WF5_SERIAL { public: static unsigned serial; };
566 template<typename T1, typename T2, typename T3, typename T4, typename T5>
567 inline GiNaC::function WF(const T1 & p1, const T2 & p2, const T3 & p3, const T4 & p4, const T5 & p5) {
568 return GiNaC::function(WF5_SERIAL::serial, ex(p1), ex(p2), ex(p3), ex(p4), ex(p5));
569 }
570
571 class iWF1_SERIAL { public: static unsigned serial; };
572 template<typename T1>
573 inline GiNaC::function iWF(const T1 & p1) {
574 return GiNaC::function(iWF1_SERIAL::serial, ex(p1));
575 }
576
577 class iWF2_SERIAL { public: static unsigned serial; };
578 template<typename T1, typename T2>
579 inline GiNaC::function iWF(const T1 & p1, const T2 & p2) {
580 return GiNaC::function(iWF2_SERIAL::serial, ex(p1), ex(p2));
581 }
582
583 class iWF3_SERIAL { public: static unsigned serial; };
584 template<typename T1, typename T2, typename T3>
585 inline GiNaC::function iWF(const T1 & p1, const T2 & p2, const T3 & p3) {
586 return GiNaC::function(iWF3_SERIAL::serial, ex(p1), ex(p2), ex(p3));
587 }
588
589 class iWF4_SERIAL { public: static unsigned serial; };
590 template<typename T1, typename T2, typename T3, typename T4>
591 inline GiNaC::function iWF(const T1 & p1, const T2 & p2, const T3 & p3, const T4 & p4) {
592 return GiNaC::function(iWF4_SERIAL::serial, ex(p1), ex(p2), ex(p3), ex(p4));
593 }
594
595 class iWF5_SERIAL { public: static unsigned serial; };
596 template<typename T1, typename T2, typename T3, typename T4, typename T5>
597 inline GiNaC::function iWF(const T1 & p1, const T2 & p2, const T3 & p3, const T4 & p4, const T5 & p5) {
598 return GiNaC::function(iWF5_SERIAL::serial, ex(p1), ex(p2), ex(p3), ex(p4), ex(p5));
599 }
600
601 #endif
602
603 // Helper to introduce new GiNaC function
604 inline std::function<GiNaC::function(const ex &)> GiNaC_Function_1(const string name) {
605 for (auto & it : GiNaC::function::get_registered_functions()) {
606 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
607 }
608 unsigned s = GiNaC::function::register_new(function_options(name,1).do_not_evalf_params());
609 return [s](const ex &p1)->GiNaC::function { return GiNaC::function(s,p1); };
610 }
611
612 inline std::function<GiNaC::function(const ex &,const ex &)> GiNaC_Function_2(const string name) {
613 for (auto & it : GiNaC::function::get_registered_functions()) {
614 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
615 }
616 unsigned s = GiNaC::function::register_new(function_options(name,2).do_not_evalf_params());
617 return [s](const ex &p1,const ex &p2)->GiNaC::function { return GiNaC::function(s,p1,p2); };
618 }
619
620 inline std::function<GiNaC::function(const ex &,const ex &,const ex &)> GiNaC_Function_3(const string name) {
621 for (auto & it : GiNaC::function::get_registered_functions()) {
622 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
623 }
624 unsigned s = GiNaC::function::register_new(function_options(name,3).do_not_evalf_params());
625 return [s](const ex &p1,const ex &p2,const ex &p3)->GiNaC::function { return GiNaC::function(s,p1,p2,p3); };
626 }
627
628 inline std::function<GiNaC::function(const ex &,const ex &,const ex &,const ex &)> GiNaC_Function_4(const string name) {
629 for (auto & it : GiNaC::function::get_registered_functions()) {
630 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
631 }
632 unsigned s = GiNaC::function::register_new(function_options(name,4).do_not_evalf_params());
633 return [s](const ex &p1,const ex &p2,const ex &p3,const ex &p4)->GiNaC::function { return GiNaC::function(s,p1,p2,p3,p4); };
634 }
635
636 inline std::function<GiNaC::function(const ex &,const ex &,const ex &,const ex &,const ex &)> GiNaC_Function_5(const string name) {
637 for (auto & it : GiNaC::function::get_registered_functions()) {
638 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
639 }
640 unsigned s = GiNaC::function::register_new(function_options(name,5).do_not_evalf_params());
641 return [s](const ex &p1,const ex &p2,const ex &p3,const ex &p4,const ex &p5)->GiNaC::function { return GiNaC::function(s,p1,p2,p3,p4,p5); };
642 }
643
644 inline std::function<GiNaC::function(const ex &,const ex &,const ex &,const ex &,const ex &,const ex &)> GiNaC_Function_6(const string name) {
645 for (auto & it : GiNaC::function::get_registered_functions()) {
646 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
647 }
648 unsigned s = GiNaC::function::register_new(function_options(name,6).do_not_evalf_params());
649 return [s](const ex &p1,const ex &p2,const ex &p3,const ex &p4,const ex &p5,const ex &p6)->GiNaC::function { return GiNaC::function(s,p1,p2,p3,p4,p5,p6); };
650 }
651
652 inline std::function<GiNaC::function(const ex &,const ex &,const ex &,const ex &,const ex &,const ex &,const ex &)> GiNaC_Function_7(const string name) {
653 for (auto & it : GiNaC::function::get_registered_functions()) {
654 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
655 }
656 unsigned s = GiNaC::function::register_new(function_options(name,7).do_not_evalf_params());
657 return [s](const ex &p1,const ex &p2,const ex &p3,const ex &p4,const ex &p5,const ex &p6,const ex &p7)->GiNaC::function { return GiNaC::function(s,p1,p2,p3,p4,p5,p6,p7); };
658 }
659
660 inline std::function<GiNaC::function(const ex &,const ex &,const ex &,const ex &,const ex &,const ex &,const ex &,const ex &)> GiNaC_Function_8(const string name) {
661 for (auto & it : GiNaC::function::get_registered_functions()) {
662 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
663 }
664 unsigned s = GiNaC::function::register_new(function_options(name,8).do_not_evalf_params());
665 return [s](const ex &p1,const ex &p2,const ex &p3,const ex &p4,const ex &p5,const ex &p6,const ex &p7,const ex &p8)->GiNaC::function { return GiNaC::function(s,p1,p2,p3,p4,p5,p6,p7,p8); };
666 }
667
668 inline std::function<GiNaC::function(const ex &,const ex &,const ex &,const ex &,const ex &,const ex &,const ex &,const ex &,const ex &)> GiNaC_Function_9(const string name) {
669 for (auto & it : GiNaC::function::get_registered_functions()) {
670 if (it.get_name() == name) throw Error("Function named "+name+" already exists!");
671 }
672 unsigned s = GiNaC::function::register_new(function_options(name,9).do_not_evalf_params());
673 return [s](const ex &p1,const ex &p2,const ex &p3,const ex &p4,const ex &p5,const ex &p6,const ex &p7,const ex &p8,const ex &p9)->GiNaC::function { return GiNaC::function(s,p1,p2,p3,p4,p5,p6,p7,p8,p9); };
674 }
675
679 class MapFunction : public map_function {
680 public:
681 ex operator()(const ex &e);
682 MapFunction(std::function<ex(const ex &, MapFunction &)>);
683 static ex subs(const ex & expr, const ex & pat, std::function<ex(const ex &)> f);
684 private:
685 std::function<ex(const ex &, MapFunction &)> Function;
686 };
687
688
692 class Parser {
693 public:
694 prototype_table FTable;
695 symtab STable;
696 ex Read(const string & instr,bool s2S=true);
697 ex ReadFile(string filename,bool s2S=true);
698 Parser();
699 Parser(symtab st);
700 };
701
702 /*-----------------------------------------------------*/
703 // isFunction
704 /*-----------------------------------------------------*/
705 inline bool isFunction(const ex &e, string func_name) {
706 return is_a<GiNaC::function>(e) && ex_to<GiNaC::function>(e).get_name()==func_name;
707 }
708 inline bool isFunction(const ex &e, string func_name, int nargs) {
709 return is_a<GiNaC::function>(e) && ex_to<GiNaC::function>(e).get_name()==func_name && (e.nops()-nargs)==0;
710 }
711
712 /*-----------------------------------------------------*/
713 // hasFunction
714 /*-----------------------------------------------------*/
715 inline bool has_function(const ex & expr) {
716 for(const_preorder_iterator i = expr.preorder_begin(); i != expr.preorder_end(); ++i) {
717 if(is_a<GiNaC::function>(*i)) return true;
718 }
719 return false;
720 }
721
722 // tree traversal
723 inline void PreTree(const ex & e, std::function<void(const ex &)> f) {
724 for(const_preorder_iterator i = e.preorder_begin(); i != e.preorder_end(); ++i) f(*i);
725 }
726 inline void PostTree(const ex & e, std::function<void(const ex &)> f) {
727 for(const_postorder_iterator i = e.postorder_begin(); i != e.postorder_end(); ++i) f(*i);
728 }
729
730 /*-----------------------------------------------------*/
731 // string Functions
732 /*-----------------------------------------------------*/
733 void string_replace_all(string &str, const string &from, const string &to);
734 void string_trim(string &str);
735 bool string_start_with(const string & fstr, const string & sstr);
736 bool string_end_with(const string & fstr, const string & estr);
737 bool string_contain(const string & fstr, const string & mstr);
738
739 void Combinations(int n, int m, std::function<void(const int*)> f);
740 void CombinationsR(int n, int m, std::function<void(const int*)> f);
741 void Permutations(int n, std::function<void(const int*)> f);
742 void Permutations(int n, int m, std::function<void(const int*)> f);
743 void PermutationsR(int n, int m, std::function<void(const int*)> f);
744 bool isSorted(const lst & exs);
745 bool isSorted(int n, const ex exs[]);
746 int ACSort(lst & exs);
747 int ACSort(int n, ex exs[]);
748
749 /*-----------------------------------------------------*/
750 // Rationalize
751 /*-----------------------------------------------------*/
752 void set_precision(long prec,bool push=true);
753 void reset_precision();
754 long get_precision();
755 ex Rationalize(const ex & e, int dn=Digits);
756
757 /*-----------------------------------------------------*/
758 // sort
759 /*-----------------------------------------------------*/
760 long long node_number(const ex & expr, int level=0);
761 bool ex_less(const ex &a, const ex &b);
762 void sort_lst(lst & ilst, bool less=true);
763 void sort_lst_by(lst & ilst, int n, bool less=true);
764 void sort_vec(exvector & ivec, bool less=true);
765 void sort_vec_by(exvector & ivec, int n, bool less=true);
766
767 /*-----------------------------------------------------*/
768 // Other Functions
769 /*-----------------------------------------------------*/
770 inline void append_to(const exvector & exv, lst & alst) { for(auto item : exv) alst.append(item); }
771 inline void append_to(const lst & alst, exvector & exv) { for(auto item : alst) exv.push_back(item); }
772 inline lst CoPat(const ex & e, std::function<bool(const ex &)> f) {
773 if(is_a<mul>(e)) {
774 ex cc=1, vv=1;
775 for(auto item : e) {
776 if(f(item)) vv *= item;
777 else cc *= item;
778 }
779 return lst{cc,vv};
780 } else if(f(e)) return lst{1,e};
781 else return lst{e,1};
782 }
783
787 class XIntegral : public basic {
788 //GINAC_DECLARE_REGISTERED_CLASS(XIntegral, basic)
789 private:
790 static GiNaC::registered_class_info reg_info;
791 public:
792 static GiNaC::registered_class_info &get_class_info_static();
793 class visitor {
794 public:
795 virtual void visit(const XIntegral &) = 0; // classname
796 virtual ~visitor();
797 };
798 template<class B, typename... Args> friend B & dynallocate(Args &&... args);
799 typedef basic inherited; // supername
800 XIntegral(); // classname
801 XIntegral * duplicate() const override; // classname
802 void accept(GiNaC::visitor & v) const override;
803 const GiNaC::registered_class_info &get_class_info() const override;
804 GiNaC::registered_class_info &get_class_info() override;
805 const char *class_name() const override;
806 protected:
807 int compare_same_type(const GiNaC::basic & other) const override;
808 // GINAC_DECLARE_REGISTERED_CLASS END
809
810 public:
811 ex Function=lst{};
812 ex Exponent=lst{};
813 ex Deltas=lst{};
814 size_t nops() const override;
815 ex op(size_t i) const override;
816 ex & let_op(size_t i) override;
817 void print(const print_dflt &c, unsigned level = 0) const;
818 void archive(archive_node & n) const override;
819 void read_archive(const archive_node& n) override;
820 static bool has(const ex &e);
821 static lst all(const ex &e);
822 XIntegral(ex fed);
823 XIntegral(ex loops, ex ps, ex ns);
824 };
825
826 #ifndef DOXYGEN_SKIP
827 class _global_init {
828 public:
829 class _init {
830 public: _init();
831 };
832 private:
833 static _init init_object;
834 };
835 #endif
836
837 /*-----------------------------------------------------*/
838 // Interface to FORM & Fermat
839 /*-----------------------------------------------------*/
840
844 class Fermat {
845 public:
846 static Fermat& get();
847 static int buffer_size;
848 string Sentinel = "---EOF---";
849 void Init(string fer_path="fer64");
850 int vmax = 0;
851 string Execute(string);
852 void Exit();
853 ~Fermat();
854
855 private:
856 bool inited = false;
857 bool exited = false;
858 int P2C[2];
859 int C2P[2];
860 pid_t fpid = 0;
861 pid_t pid = 0;
862 };
863
867 class Form {
868 public:
869 static int buffer_size;
870 string Sentinel = "---EOF---";
871 string Prompt = "***EOF***";
872 void Init(string form_path="form");
873 string Execute(const string & script, const string & out_var="[o]");
874 void Exit();
875 ~Form();
876
877 private:
878 bool inited = false;
879 bool exited = false;
880 int io[2][2];
881 int stdo[2];
882 pid_t fpid = 0;
883 pid_t pid = 0;
884 };
885
886
890 class MMAFormat : public print_dflt {
891 GINAC_DECLARE_PRINT_CONTEXT(MMAFormat, print_dflt)
892 public:
893 MMAFormat(ostream &os, unsigned opt=0);
894
895 template<class T> const MMAFormat & operator << (const T & v) const {
896 s << v;
897 return *this;
898 };
899 const MMAFormat & operator << (const basic & v) const;
900 const MMAFormat & operator << (const ex & v) const;
901 const MMAFormat & operator << (const lst & v) const;
902 const MMAFormat & operator<<(std::ostream& (*v)(std::ostream&)) const;
903 const MMAFormat & operator << (const matrix & v) const;
904 const MMAFormat & operator << (const exvector & v) const;
905 const MMAFormat & operator << (const exmap & v) const;
906 const MMAFormat & operator << (const exset & v) const;
907 };
908 extern MMAFormat mout;
909
910 void garWrite(const exvector &exv, string garfn);
911 inline void garWrite(string garfn, const exvector &exv) { garWrite(exv,garfn); }
912 void garRead(exvector &exv, string garfn);
913 inline void garRead(string garfn, exvector &exv) { garRead(exv, garfn); }
914 ex add_collect_normal(const exvector &exv, ex const &pats, int opt = o_flint);
915 ex add_collect_normal(const exvector &exv, lst const &pats, int opt = o_flint);
916 ex add_collect_normal(const exvector &exv, init_list const &pats, int opt = o_flint);
917 ex add_collect_normal(const ex & e, ex const &pats, int opt = o_flint);
918 ex add_collect_normal(const ex & e, lst const &pats, int opt = o_flint);
919 ex add_collect_normal(const ex & e, init_list const &pats, int opt = o_flint);
920 bool has_w(const ex & e);
921 void subs_w(exmap & repl);
922 void subs_w(lst & repl);
923
924 class Server {
925 public:
926 int Round = 3;
927 int Port = 0;
928 unsigned Total;
929 void Start();
930 int Verbose = 1;
931 string Skip = "[ID].run";
932 string DL;
933 string FUNC;
934
935 static string Next(string sip, string sport);
936 };
937
938 void ReShare(const ex & e);
939 void ReShare(const lst & e);
940 void ReShare(const ex & e1, const ex & e2);
941 void ReShare(const ex & e1, const ex & e2, const ex & e3);
942 void ReShare(const exvector & ev);
943 void ReShare(const exvector & ev1, const exvector & ev2);
944
945 ex nextprime(const ex & n);
946 ex nextprime(int n);
947 numeric RationalReconstruct(numeric a, numeric p);
948 numeric mulInv(numeric a, numeric b);
949 numeric ChineseRemainder(std::vector<numeric> a, std::vector<numeric> n);
950 numeric RationalReconstruct(vector<numeric> aa, vector<numeric> pp);
951 ex Thiele(const exvector & keys, const exvector & values, const ex & d);
952 ex Newton(const exvector & keys, const exvector & values, const ex & d, const ex factor=1);
953
954 // fermat functions
955 matrix fermat_Redrowech(const matrix & mat);
956 matrix fermat_Redrowech_Sparse(const matrix & mat);
957 ex fermat_Det(const matrix & mat);
958 ex fermat_Det_Sparse(const matrix & mat);
959 matrix fermat_inv(const matrix & mat);
960 matrix fermat_mul(const matrix & m1, const matrix & m2);
961 matrix fermat_pow(const matrix & mat_in, int n);
962
963 void fermat_mat(const matrix & mat_in, const string & name);
964 matrix fermat_mat(const string & name);
965 void fermat_eval(const string & fcmd="@[**]");
966 bool has_symbol(const ex & e);
967 void arg2map(int argc, char** argv, const char *optstring, std::map<char,std::string> & kv);
968
969 // other helpers
970 std::string get_hostname();
971 std::string get_env(const std::string & name);
972
973 // chop
974 ex chop(const ex & e, const ex & err);
975
976}
977
978typedef void (*RUN)(std::string dir_id);
979
980#include "Symbols.h"
981#include "PoolPipe.h"
int * a
void(* RUN)(std::string dir_id)
Definition BASIC.h:978
PoolPipe header file.
Basic header file.
class used to wrap error message
Definition BASIC.h:245
string msg
Definition BASIC.h:247
const char * what() const
Definition BASIC.cpp:24
interface to communicate with Fermat program
Definition BASIC.h:844
static int buffer_size
Definition BASIC.h:847
interface to communicate with Form program
Definition BASIC.h:867
static int buffer_size
Definition BASIC.h:869
class for Mathematica Format Output
Definition BASIC.h:890
class to wrap map_function of GiNaC
Definition BASIC.h:679
class to parse for string or file, helpful with Symbol class
Definition BASIC.h:692
prototype_table FTable
Definition BASIC.h:694
symtab STable
Definition BASIC.h:695
unsigned Total
Definition BASIC.h:928
string FUNC
Definition BASIC.h:933
string DL
Definition BASIC.h:932
virtual void visit(const Symbol &)=0
class extended to GiNaC symbol class, represent a positive symbol
Definition BASIC.h:116
void unset() const
Definition BASIC.cpp:140
static void unset_all()
Definition BASIC.cpp:146
symbol inherited
Definition BASIC.h:128
static lst all(const ex &e)
ex series(const relational &s, int order, unsigned options=0) const override
Definition BASIC.cpp:125
void archive(archive_node &n) const override
Symbol archive.
Definition BASIC.cpp:88
ex imag_part() const override
Definition BASIC.cpp:104
Symbol * duplicate() const override
Definition BASIC.cpp:61
bool is_equal_same_type(const basic &other) const override
Definition BASIC.cpp:113
ex conjugate() const override
Definition BASIC.cpp:102
static ex set_all(const ex &expr)
Definition BASIC.cpp:147
const char * class_name() const override
Definition BASIC.cpp:65
static bool has(const ex &e)
ex subs(const exmap &m, unsigned options=0) const override
Definition BASIC.h:148
void read_archive(const archive_node &n) override
Symbol read_archive.
Definition BASIC.cpp:96
static GiNaC::registered_class_info & get_class_info_static()
Definition BASIC.cpp:59
ex derivative(const symbol &s) const override
Definition BASIC.cpp:119
unsigned calchash() const override
Definition BASIC.cpp:105
ex evalf() const override
Definition BASIC.cpp:101
void set(const ex &v) const
Definition BASIC.cpp:139
static std::map< std::string, ex > Table
Definition BASIC.h:163
ex eval() const override
Definition BASIC.cpp:100
unsigned get_serial()
Definition BASIC.h:168
friend B & dynallocate(Args &&... args)
unsigned get_domain() const override
Definition BASIC.h:159
void set_name(string n)
Definition BASIC.cpp:137
void accept(GiNaC::visitor &v) const override
Definition BASIC.cpp:62
static exmap vmap
Definition BASIC.h:170
ex real_part() const override
Definition BASIC.cpp:103
int compare_same_type(const GiNaC::basic &other) const override
Definition BASIC.cpp:75
const GiNaC::registered_class_info & get_class_info() const override
Definition BASIC.cpp:63
virtual void visit(const XIntegral &)=0
XIntegral Class, preface to SecDec.
Definition BASIC.h:787
basic inherited
Definition BASIC.h:799
static lst all(const ex &e)
static bool has(const ex &e)
friend B & dynallocate(Args &&... args)
virtual void visit(const iSymbol &)=0
class extended to GiNaC symbol class, pure imaginary symbol
Definition BASIC.h:186
bool is_equal_same_type(const basic &other) const override
Definition BASIC.cpp:188
ex eval() const override
Definition BASIC.cpp:236
ex evalf() const override
Definition BASIC.cpp:237
static std::map< std::string, ex > Table
Definition BASIC.h:233
unsigned get_domain() const override
Definition BASIC.h:214
void archive(archive_node &n) const override
Symbol archive.
Definition BASIC.cpp:224
ex subs(const exmap &m, unsigned options=0) const override
Definition BASIC.h:220
void set_name(string n)
Definition BASIC.cpp:212
iSymbol * duplicate() const override
Definition BASIC.cpp:166
ex real_part() const override
Definition BASIC.cpp:239
ex derivative(const symbol &s) const override
Definition BASIC.cpp:194
static GiNaC::registered_class_info & get_class_info_static()
Definition BASIC.cpp:164
ex conjugate() const override
Definition BASIC.cpp:238
static lst all(const ex &e)
const char * class_name() const override
Definition BASIC.cpp:170
ex series(const relational &s, int order, unsigned options=0) const override
Definition BASIC.cpp:200
void accept(GiNaC::visitor &v) const override
Definition BASIC.cpp:167
ex imag_part() const override
Definition BASIC.cpp:240
symbol inherited
Definition BASIC.h:198
const GiNaC::registered_class_info & get_class_info() const override
Definition BASIC.cpp:168
int compare_same_type(const GiNaC::basic &other) const override
Definition BASIC.cpp:179
static bool has(const ex &e)
friend B & dynallocate(Args &&... args)
void read_archive(const archive_node &n) override
Symbol read_archive.
Definition BASIC.cpp:232
unsigned calchash() const override
Definition BASIC.cpp:214
class as lst Helper
Definition BASIC.h:258
static lst map(const lst &m, F f)
Definition BASIC.h:273
static void map_inplace(lst &m, F f)
Definition BASIC.h:266
HepLib namespace.
Definition BASIC.cpp:17
ex expand_ex(ex const &expr_in, std::function< bool(const ex &)> has_func)
the expand like Mathematica
Definition BASIC.cpp:1189
const char * Color_HighLight
Definition BASIC.cpp:248
string INC_FLAGS
Definition Init.cpp:169
ex exfactor(const ex &expr_in, int opt)
factorize a expression
Definition BASIC.cpp:1855
ex collect_factors(const ex &expr)
a wrapper for collect_common_factors, catch errors
Definition BASIC.cpp:1842
ex w9
Definition BASIC.h:503
ex w8
Definition BASIC.h:503
matrix fermat_Redrowech_Sparse(const matrix &mat)
Definition Fermat.cpp:516
void append_to(const exvector &exv, lst &alst)
Definition BASIC.h:770
bool ex_less(const ex &a, const ex &b)
Definition Sort.cpp:10
void PostTree(const ex &e, std::function< void(const ex &)> f)
Definition BASIC.h:726
const int o_flint_ccf
Definition Init.cpp:114
void arg2map(int argc, char **argv, const char *optstring, std::map< char, std::string > &kv)
Definition BASIC.cpp:2341
__float128 ex2q(ex num)
ex of numeric to __float128
Definition BASIC.cpp:880
const iSymbol iEpsilon
void reset_precision()
Definition BASIC.cpp:2327
ex w7
Definition BASIC.h:503
ex EvalF(ex expr)
the nuerical evaluation, Digits=100 will be used
Definition BASIC.cpp:1246
lst str2lst(const string &expr, symtab stab)
convert string to the lst, using Parser internally
Definition BASIC.cpp:694
matrix fermat_mul(const matrix &m1, const matrix &m2)
Definition Fermat.cpp:987
ex exnd(const ex &expr, int opt)
num_den a expression
Definition BASIC.cpp:1936
MMAFormat mout
ex form_factor(const ex &expr, bool nd=true)
Definition BASIC.h:476
bool has_function(const ex &expr)
Definition BASIC.h:715
const int o_flintf_ccf
Definition Init.cpp:116
lst gather_symbols(const ex &e)
get all symbols from input expression
Definition BASIC.cpp:540
lst CoPat(const ex &e, std::function< bool(const ex &)> f)
Definition BASIC.h:772
ex w5
Definition BASIC.h:503
void let_op_prepend(ex &ex_in, const ex item)
preppend item into expression
Definition BASIC.cpp:1336
std::function< GiNaC::function(const ex &, const ex &, const ex &, const ex &)> GiNaC_Function_4(const string name)
Definition BASIC.h:628
std::function< GiNaC::function(const ex &, const ex &, const ex &)> GiNaC_Function_3(const string name)
Definition BASIC.h:620
bool match_any(ex expr, lst ps)
Definition BASIC.h:69
ex EvalL(ex expr)
Definition BASIC.cpp:1257
lst xlst(int bi, int ei)
return a lst: x(bi), x(bi+1), ..., x(ei)
Definition BASIC.cpp:947
int GiNaC_Parallel_Process
Definition Init.cpp:150
void let_op(ex &ex_in, int index1, int index2, const ex item)
update index1-th.index2-th of expression with item
Definition BASIC.cpp:1561
std::function< GiNaC::function(const ex &)> GiNaC_Function_1(const string name)
Definition BASIC.h:604
std::initializer_list< ex > init_list
Definition BASIC.h:47
bool string_contain(const string &fstr, const string &mstr)
ex q2ex(__float128 num)
__float128 to ex
Definition BASIC.cpp:868
bool xPositive(ex const expr)
check the expr is xPositive, i.e., each x-monomial item is postive
Definition BASIC.cpp:1291
void Combinations(int n, int m, std::function< void(const int *)> f)
const int o_form
Definition Init.cpp:112
void PreTree(const ex &e, std::function< void(const ex &)> f)
Definition BASIC.h:723
int NNDigits
Definition Init.cpp:162
const int o_fermat
Definition Init.cpp:109
void ex2file(const ex &expr, string filename)
export expression file
Definition BASIC.cpp:846
const int o_none
Definition Init.cpp:107
ex normal_fermat(const ex &expr, bool dfactor)
return the normalizatied expression, using fermat_numer_denom
Definition BASIC.cpp:1832
ex NN(ex expr, int digits)
the nuerical evaluation
Definition BASIC.cpp:1279
const int o_flint
Definition Init.cpp:113
string Version
Definition Init.cpp:85
ex w0
Definition BASIC.h:503
map< string, bool > GiNaC_Parallel_RM
Definition Init.cpp:155
bool isSorted(const lst &exs)
bool is_equal_any(ex expr, lst ps)
Definition BASIC.h:64
std::function< GiNaC::function(const ex &, const ex &, const ex &, const ex &, const ex &, const ex &, const ex &, const ex &, const ex &)> GiNaC_Function_9(const string name)
Definition BASIC.h:668
ex factor_flint(const ex &e, bool nd=true)
map< ex, long long, ex_is_less > fermat_weight
Definition Init.cpp:159
bool has_all(ex expr, lst ps)
Definition BASIC.h:59
const char * ErrColor
Definition BASIC.cpp:246
numeric RationalReconstruct(numeric a, numeric p)
Definition Rational.cpp:8
const int o_fermatfD
Definition Init.cpp:110
ex Thiele(const exvector &keys, const exvector &values, const ex &d)
Definition Rational.cpp:81
ex collect_ex(ex const &expr_in, std::function< bool(const ex &)> has_func, int opt)
the collect function like Mathematica
Definition BASIC.cpp:1203
ex EvalQ(ex expr)
Definition BASIC.cpp:1262
void garRead(const string &garfn, map< string, ex > &resMap)
garRead from file, and output in a map
Definition BASIC.cpp:592
map< string, int > GiNaC_Parallel_NB
Definition Init.cpp:154
void subs_w(exmap &repl)
Definition BASIC.cpp:2242
std::function< GiNaC::function(const ex &, const ex &, const ex &, const ex &, const ex &, const ex &, const ex &, const ex &)> GiNaC_Function_8(const string name)
Definition BASIC.h:660
const int o_fermat_form
Definition Init.cpp:121
void ReShare(const ex &e)
Definition BASIC.cpp:2254
bool file_exists(string fn)
Definition BASIC.h:292
ex w4
Definition BASIC.h:503
bool has_w(const ex &e)
Definition BASIC.cpp:2237
ex factor_form(const ex &expr, bool nd)
factorize a expression using FORM
Definition BASIC.cpp:2052
int GiNaC_Parallel_Level
Definition Init.cpp:149
ex series_ex(ex const &expr_in, ex const &s0, int sn0)
the series like Mathematica, include s^n
Definition BASIC.cpp:969
bool string_start_with(const string &fstr, const string &sstr)
const char * WarnColor
Definition BASIC.cpp:247
ex str2ex(const string &expr, symtab stab)
convert string to ex expression, using Parser internally
Definition BASIC.cpp:671
int ACSort(lst &exs)
numeric ChineseRemainder(std::vector< numeric > a, std::vector< numeric > n)
Definition Rational.cpp:53
bool key_exists(const exmap &map, const ex &key)
Definition BASIC.h:296
string LIB_FLAGS
Definition Init.cpp:170
ex form_eval(const ex &expr)
Definition BASIC.cpp:1942
bool using_cache
Definition Init.cpp:160
void fermat_mat(const matrix &mat_in, const string &name)
Definition Fermat.cpp:1224
string now(bool use_date)
date/time string
Definition BASIC.cpp:526
bool Debug
Definition Init.cpp:147
ex numer_denom_fermat(const ex &expr, bool dfactor=false)
return the numerator and denominator after normalization
Definition Fermat.cpp:23
bool has_any(ex expr, lst ps)
Definition BASIC.h:55
string RunOS(const string &cmd)
run symtem command and return the output as string
Definition BASIC.cpp:572
lst add2lst(const ex &expr)
convert add to lst
Definition BASIC.cpp:922
ex w
Definition Init.cpp:93
ex fermat_normal(const ex &expr, bool dfactor=false)
Definition BASIC.h:469
const Symbol d
int fermat_using_array
Definition Init.cpp:158
int CpuCores()
return the cpu cores using OpenMP
Definition BASIC.cpp:1821
map< string, int > GiNaC_Parallel_NP
Definition Init.cpp:151
bool isFunction(const ex &e, string func_name)
Definition BASIC.h:705
map< string, int > GiNaC_Parallel_Verb
Definition Init.cpp:152
void CombinationsR(int n, int m, std::function< void(const int *)> f)
map< string, bool > GiNaC_Parallel_ReWR
Definition Init.cpp:157
exvector lst2vec(const lst &alst)
convert lst to exvector
Definition BASIC.cpp:912
const int o_normal
Definition Init.cpp:108
ex get_op(const ex ex_in, int index1, int index2)
return index1-th.index2-th of expression
Definition BASIC.cpp:1607
bool match_all(ex expr, lst ps)
Definition BASIC.h:73
vector< string > file2strvec(string filename, bool skip_empty)
read file content to string vector
Definition BASIC.cpp:810
string in2str(int i)
Definition BASIC.h:350
matrix fermat_Redrowech(const matrix &mat)
Definition Fermat.cpp:409
ex file2ex(string filename)
read file content to ex
Definition BASIC.cpp:826
ex exnormal(const ex &expr, int opt)
normalize a expression
Definition BASIC.cpp:1920
const int o_flintf
Definition Init.cpp:115
const int o_flintfD_ccf
Definition Init.cpp:118
const int o_flintfD
Definition Init.cpp:117
ex EvalMP(ex expr)
Definition BASIC.cpp:1267
const int o_normal_fermat
Definition Init.cpp:119
std::function< GiNaC::function(const ex &, const ex &)> GiNaC_Function_2(const string name)
Definition BASIC.h:612
ex nextprime(const ex &n)
Definition BASIC.cpp:2288
string InstallPrefix
Definition Init.cpp:168
void Permutations(int n, std::function< void(const int *)> f)
ex normal_flint(const ex &expr, int opt=o_flint)
void sort_lst_by(lst &ilst, int n, bool less=true)
sort the list in less order, or the reverse
Definition Sort.cpp:91
const ex iEpsilonN
Definition Init.cpp:144
bool In_GiNaC_Parallel
Definition Init.cpp:148
ex fermat_eval(const ex &expr)
return the numerator and denominator after normalization
Definition Fermat.cpp:317
ex fermat_Det(const matrix &mat)
Definition Fermat.cpp:650
lst mul2lst(const ex &expr)
convert mul to lst
Definition BASIC.cpp:934
matrix fermat_inv(const matrix &mat)
Definition Fermat.cpp:880
std::function< GiNaC::function(const ex &, const ex &, const ex &, const ex &, const ex &, const ex &)> GiNaC_Function_6(const string name)
Definition BASIC.h:644
std::function< GiNaC::function(const ex &, const ex &, const ex &, const ex &, const ex &, const ex &, const ex &)> GiNaC_Function_7(const string name)
Definition BASIC.h:652
string file2str(string filename)
read file content to string
Definition BASIC.cpp:776
std::function< GiNaC::function(const ex &, const ex &, const ex &, const ex &, const ex &)> GiNaC_Function_5(const string name)
Definition BASIC.h:636
lst collect_lst(ex const &expr_in, std::function< bool(const ex &)> has_func, int opt)
the collect function like Mathematica, reture the lst { {c1,v1}, {c2,v2}, ... }
Definition BASIC.cpp:1223
void sort_vec(exvector &ivec, bool less=true)
sort the list in less order, or the reverse
Definition Sort.cpp:54
ex diff_ex(ex const expr, ex const xp, unsigned nth, bool expand)
the differential like Mathematica
Definition BASIC.cpp:1064
int Verbose
Definition Init.cpp:145
void sort_lst(lst &ilst, bool less=true)
sort the list in less order, or the reverse
Definition Sort.cpp:79
ex Rationalize(const ex &e, int dn)
Definition BASIC.cpp:2297
bool file_remove(string fn)
Definition BASIC.h:288
void string_replace_all(string &str, const string &from, const string &to)
void garWrite(const string &garfn, const map< string, ex > &resMap)
garWrite to write the string-key map to the archive
Definition BASIC.cpp:640
void let_op_append(ex &ex_in, const ex item)
append item into expression
Definition BASIC.cpp:1325
lst vec2lst(const exvector &ev)
convert exvector to lst
Definition BASIC.cpp:903
string ex2str(const ex &expr)
convert ex to output string, the defalut printer format will be used
Definition BASIC.cpp:716
void let_op_remove_first(ex &ex_in)
remove first from expression
Definition BASIC.cpp:1356
matrix lst2mat(const lst &ls)
convert 2Dim lst to matrix
Definition BASIC.cpp:738
bool dir_exists(string dir)
Definition BASIC.h:300
long long node_number(const ex &expr, int level=0)
void str2file(const string &ostr, string filename)
export string to a file
Definition BASIC.cpp:788
const int o_normal_form
Definition Init.cpp:120
long long cache_limit
Definition Init.cpp:161
bool string_end_with(const string &fstr, const string &estr)
ex w1
Definition BASIC.h:503
unsigned nopat
Definition Init.cpp:91
ex w3
Definition BASIC.h:503
void set_precision(long prec, bool push)
Definition BASIC.cpp:2318
ex w6
Definition BASIC.h:503
void sort_vec_by(exvector &ivec, int n, bool less=true)
sort the list in less order, or the reverse
Definition Sort.cpp:67
ex add_collect_normal(const exvector &exv, ex const &pats, int opt)
Definition BASIC.cpp:2177
ex fermat_Det_Sparse(const matrix &mat)
Definition Fermat.cpp:757
ex chop(const ex &expr, const ex &err)
Definition BASIC.cpp:2379
map< string, string > GiNaC_Parallel_PRE
Definition Init.cpp:156
std::vector< std::string > split(const std::string &s, char delimiter)
split the string into serveral part, separated by the delimiter
Definition BASIC.cpp:500
int xSign(ex const expr)
the always sign for expr
Definition BASIC.cpp:1313
exvector GiNaC_Parallel(int ntotal, std::function< ex(int)> f, const string &key)
GiNaC Parallel Evaluation using fork.
Definition BASIC.cpp:259
string get_hostname()
Definition BASIC.cpp:2363
void let_op_remove_last(ex &ex_in)
remove last from expression
Definition BASIC.cpp:1346
const int o_fermatN
Definition Init.cpp:111
bool has_symbol(const ex &e)
Definition BASIC.cpp:2357
ex w2
Definition BASIC.h:503
void PermutationsR(int n, int m, std::function< void(const int *)> f)
string get_env(const string &name)
Definition BASIC.cpp:2373
long get_precision()
Definition BASIC.cpp:2337
void string_trim(string &str)
ex numer_fermat(const ex &expr)
Definition Fermat.cpp:170
ex fermat_numer_denom(const ex &expr, bool dfactor=false)
Definition BASIC.h:465
numeric mulInv(numeric a, numeric b)
Definition Rational.cpp:31
matrix fermat_pow(const matrix &mat_in, int n)
Definition Fermat.cpp:1112
string PRE
Definition Init.cpp:146
int ex2int(ex num)
ex to integer
Definition BASIC.cpp:894
ex subs(const ex &e, init_list sl)
Definition BASIC.h:51
ex Newton(const exvector &keys, const exvector &values, const ex &d, const ex factor=1)
Definition Rational.cpp:106
int GiNaC_Parallel_Batch
Definition Init.cpp:153