7 #include "ginac/parse_context.h"
17 unsigned F1_SERIAL::serial = GiNaC::function::register_new(function_options(
"F",1).
do_not_evalf_params().overloaded(2));
18 unsigned F2_SERIAL::serial = GiNaC::function::register_new(function_options(
"F",2).
do_not_evalf_params().overloaded(2));
20 unsigned WF1_SERIAL::serial = GiNaC::function::register_new(function_options(
"WF",1).
do_not_evalf_params().overloaded(5));
21 unsigned WF2_SERIAL::serial = GiNaC::function::register_new(function_options(
"WF",2).
do_not_evalf_params().overloaded(5));
22 unsigned WF3_SERIAL::serial = GiNaC::function::register_new(function_options(
"WF",3).
do_not_evalf_params().overloaded(5));
23 unsigned WF4_SERIAL::serial = GiNaC::function::register_new(function_options(
"WF",4).
do_not_evalf_params().overloaded(5));
24 unsigned WF5_SERIAL::serial = GiNaC::function::register_new(function_options(
"WF",5).
do_not_evalf_params().overloaded(5));
26 unsigned iWF1_SERIAL::serial = GiNaC::function::register_new(function_options(
"iWF",1).
do_not_evalf_params().overloaded(5));
27 unsigned iWF2_SERIAL::serial = GiNaC::function::register_new(function_options(
"iWF",2).
do_not_evalf_params().overloaded(5));
28 unsigned iWF3_SERIAL::serial = GiNaC::function::register_new(function_options(
"iWF",3).
do_not_evalf_params().overloaded(5));
29 unsigned iWF4_SERIAL::serial = GiNaC::function::register_new(function_options(
"iWF",4).
do_not_evalf_params().overloaded(5));
30 unsigned iWF5_SERIAL::serial = GiNaC::function::register_new(function_options(
"iWF",5).
do_not_evalf_params().overloaded(5));
39 return Function(e, *
this);
44 if(!e.has(pat))
return e;
45 else if(e.match(pat))
return f(e);
46 else return e.map(
self);
56 class functions_hack :
public GiNaC::function {
58 static const std::vector<function_options>& get_registered_functions() {
59 return function::registered_functions();
63 static ex sqrt_reader(
const exvector& ev) {
64 return GiNaC::sqrt(ev[0]);
67 static ex pow_reader(
const exvector& ev) {
68 return GiNaC::pow(ev[0], ev[1]);
71 static ex power_reader(
const exvector& ev) {
72 return GiNaC::power(ev[0], ev[1]);
75 static ex lst_reader(
const exvector& ev) {
76 return GiNaC::lst(ev.begin(), ev.end());
79 const prototype_table& ginac_reader() {
81 static bool initialized =
false;
82 static prototype_table reader;
84 reader.insert({{
"sqrt", 1}, reader_func(sqrt_reader)});
85 reader.insert({{
"pow", 2}, reader_func(pow_reader)});
86 reader.insert({{
"power", 2}, reader_func(power_reader)});
87 reader.insert({{
"lst", 0}, reader_func(lst_reader)});
88 enum { log, exp, sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, atan2,
89 Li2, Li3, zetaderiv, Li, S, H, lgamma, tgamma, beta, factorial, binomial, Order,
92 auto it = functions_hack::get_registered_functions().begin();
94 for ( ; serial<NFUNCTIONS; ++it, ++serial ) {
95 reader.insert({{it->get_name(), it->get_nparams()}, reader_func(serial)});
109 for(
auto item : st)
STable[item.first] = item.second;
112 string instr(in_str);
115 for (
auto & it : functions_hack::get_registered_functions()) {
116 FTable.insert({{it.get_name(), it.get_nparams()}, reader_func(serial)});
120 ex ret = ginac_parser(instr);
123 auto st = ginac_parser.get_syms();
127 if(is_exactly_a<symbol>(kv.second) &&
STable.find(kv.first)==
STable.end()) {
128 string ss = kv.first;
131 repl[kv.second] =
Symbol(ss);
134 if(redo) ret = ret.subs(repl,subs_options::no_pattern);
139 ifstream ifs(filename);
140 string ostr((istreambuf_iterator<char>(ifs)), (istreambuf_iterator<char>()));
142 return Read(ostr,s2S);
149 size_t start_pos = 0;
150 while((start_pos = str.find(from, start_pos)) != string::npos) {
151 str.replace(start_pos, from.length(), to);
152 start_pos += to.length();
157 const char* WhiteSpace =
" \t\v\r\n";
159 ostr.erase(0, ostr.find_first_not_of(WhiteSpace));
160 ostr.erase(ostr.find_last_not_of(WhiteSpace)+1);
165 if (fstr.length() >= sstr.length()) {
166 return (0 == fstr.compare (0, sstr.length(), sstr));
173 if (fstr.length() >= estr.length()) {
174 return (0 == fstr.compare (fstr.length() - estr.length(), estr.length(), estr));
181 return (fstr.find(mstr) != std::string::npos);
185 if(m<1 || m>n)
return;
186 std::string bitmask(m,1);
190 for (
int i=0; i<n; ++i) {
191 if(bitmask[i]) { is[j]=i; j++; }
194 }
while (std::prev_permutation(bitmask.begin(), bitmask.end()));
202 for(
int ni=0; ni<n; ni++) {
204 if(ni==n-1) c=(n+m-2)-isr[n-2];
205 else if(ni==0) c=isr[ni];
206 else c=isr[ni]-isr[ni-1]-1;
207 for(
int j=0; j<c; j++) is[--mi] = n-1-ni;
216 for(
int i=0; i<n; i++) pis[i]=i;
217 do { f(pis); }
while(std::next_permutation(pis,pis+n));
221 if(m<1 || m>n)
return;
225 for(
int i=0; i<m; i++) ns[i] = ns1[ns2[i]];
236 Generator(
int s,
int v) : cSlots(s) , cValues(v) {
238 for(
int i = 0; i<cSlots-1; i++)
a[i]=1-1;
243 ~Generator() {
delete []
a; }
247 if (
a[nextInd-1]==cValues-1) {
249 if(nextInd==0)
return false;
252 while (nextInd<cSlots) {
270 while (g.doNext()) f(g.a);
274 for(
int i=0; i<exs.nops()-1; i++) {
275 if(exs.op(i).is_equal(exs.op(i+1)))
continue;
276 if(!
ex_less(exs.op(i),exs.op(i+1)))
return false;
282 for(
int i=0; i<n-1; i++) {
283 if(exs[i].is_equal(exs[i+1]))
continue;
284 if(!
ex_less(exs[i],exs[i+1]))
return false;
292 for(
int i=0; i<n-1; i++)
293 for(
int j=n-1; j>i; j--)
294 if(
ex_less(exs.op(j),exs.op(j-1))) {
295 auto tmp = exs.op(j-1);
296 exs.let_op(j-1) = exs.op(j);
300 for(
int i=0; i<n-1; i++)
if(exs.op(i).is_equal(exs.op(i+1)))
return 0;
301 return (ac%2==1) ? -1 : 1;
306 for(
int i=0; i<n-1; i++)
307 for(
int j=n-1; j>i; j--)
314 for(
int i=0; i<n-1; i++)
if(exs[i].is_equal(exs[i+1]))
return 0;
315 return (ac%2==1) ? -1 : 1;
class to wrap map_function of GiNaC
static ex subs(const ex &expr, const ex &pat, std::function< ex(const ex &)> f)
ex operator()(const ex &e)
MapFunction(std::function< ex(const ex &, MapFunction &)>)
ex ReadFile(string filename, bool s2S=true)
ex Read(const string &instr, bool s2S=true)
class extended to GiNaC symbol class, represent a positive symbol
static std::map< std::string, ex > Table
do_not_evalf_params().expl_derivative_func(zd1D).derivative_func(zp1D)) REGISTER_FUNCTION(FTX
bool ex_less(const ex &a, const ex &b)
bool string_contain(const string &fstr, const string &mstr)
void Combinations(int n, int m, std::function< void(const int *)> f)
bool isSorted(const lst &exs)
bool string_start_with(const string &fstr, const string &sstr)
REGISTER_FUNCTION(Matrix, do_not_evalf_params().print_func< FCFormat >(&Matrix_fc_print).conjugate_func(mat_conj).set_return_type(return_types::commutative)) bool IsZero(const ex &e)
void CombinationsR(int n, int m, std::function< void(const int *)> f)
void Permutations(int n, std::function< void(const int *)> f)
void string_replace_all(string &str, const string &from, const string &to)
bool string_end_with(const string &fstr, const string &estr)
void PermutationsR(int n, int m, std::function< void(const int *)> f)
void string_trim(string &str)