HepLib
ExFormat.cpp
Go to the documentation of this file.
1 
6 #include "SD.h"
7 #include "cln/cln.h"
8 
9 namespace HepLib::SD {
10 
11  GINAC_IMPLEMENT_PRINT_CONTEXT(ExFormat, print_dflt)
12 
13  const ExFormat & ExFormat::operator << (const basic & v) const {
14  v.print(*this);
15  return *this;
16  }
17  const ExFormat & ExFormat::operator << (const ex & v) const {
18  v.print(*this);
19  return *this;
20  }
21  const ExFormat & ExFormat::operator << (const lst & v) const {
22  v.print(*this);
23  return *this;
24  }
25  const ExFormat & ExFormat::operator<<(std::ostream& (*v)(std::ostream&)) const {
26  s << v;
27  return *this;
28  }
29 
30  void ExFormat::print_integer(const ExFormat & c, const cln::cl_I & x) {
31  c.s << cln::cl_I_to_int(x);
32  }
33 
34  void ExFormat::print_real(const ExFormat & c, const cln::cl_R & x) {
35  if (cln::instanceof(x, cln::cl_I_ring)) {
36  print_integer(c, cln::the<cln::cl_I>(x));
37  } else if (cln::instanceof(x, cln::cl_RA_ring)) {
38  const cln::cl_I numer = cln::numerator(cln::the<cln::cl_RA>(x));
39  const cln::cl_I denom = cln::denominator(cln::the<cln::cl_RA>(x));
40  if (cln::plusp(x)) {
41  c.s << "(";
42  print_integer(c, numer);
43  c.s << "/" << c.type << "(";
44  print_integer(c, denom);
45  c.s << "))";
46  } else {
47  c.s << "(-(";
48  print_integer(c, -numer);
49  c.s << "/" << c.type << "(";
50  print_integer(c, denom);
51  c.s << ")))";
52  }
53  } else {
54  c.s << c.type << "(" << c.MQuote;
55  cln::cl_print_flags ourflags;
56  ourflags.default_float_format = cln::float_format(cln::the<cln::cl_F>(x));
57  cln::print_real(c.s, ourflags, x);
58  c.s << c.MQuote << ")";
59  }
60  }
61 
62  void ExFormat::print_numeric(const numeric & p, const ExFormat & c, unsigned level) {
63  if (p.is_real()) {
64  print_real(c, cln::the<cln::cl_R>(p.to_cl_N()));
65  } else {
66  c.s << "complex<" << c.type << ">(";
67  print_real(c, cln::realpart(p.to_cl_N()));
68  c.s << ",";
69  print_real(c, cln::imagpart(p.to_cl_N()));
70  c.s << ")";
71  }
72  }
73 
74  void ex_print_power(const power & p, const ExFormat & c, unsigned level) {
75  if (p.op(1).is_equal(ex(1)/2)) {
76  c.s << "sqrt(";
77  p.op(0).print(c);
78  c.s << ')';
79  } else {
80  c.s << "pow(";
81  p.op(0).print(c);
82  c.s << ',';
83  p.op(1).print(c);
84  c.s << ')';
85  }
86  }
87 
88  ExFormat::ExFormat(ostream &os, const string & s, unsigned opt) : print_dflt(os, opt), suffix(s) {
89  set_print_func<power, ExFormat>(ex_print_power);
90  }
91 
92 }
93 
94 
95 
SecDec header file.
const ExFormat & operator<<(const T &v) const
Definition: SD.h:339
ExFormat(ostream &os, const string &s="L", unsigned opt=0)
Definition: ExFormat.cpp:88
namespace for Numerical integration with Sector Decomposition method
Definition: AsyMB.cpp:10
void ex_print_power(const power &p, const ExFormat &c, unsigned level)
Definition: ExFormat.cpp:74