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