61integral::integral(
const ex & x_,
const ex & a_,
const ex & b_,
const ex & f_)
62 :
x(x_), a(a_), b(b_), f(f_)
64 if (!is_a<symbol>(
x)) {
65 throw(std::invalid_argument(
"first argument of integral must be of type symbol"));
75 inherited::read_archive(
n, sym_lst);
76 n.find_ex(
"x",
x, sym_lst);
77 n.find_ex(
"a",
a, sym_lst);
78 n.find_ex(
"b",
b, sym_lst);
79 n.find_ex(
"f",
f, sym_lst);
84 inherited::archive(
n);
110 string varname = ex_to<symbol>(
x).get_name();
118 if (varname.size() > 1)
119 c.s <<
"\\," << varname <<
"\\:";
121 c.s << varname <<
"\\,";
166 if (is_exactly_a<numeric>(ea) && is_exactly_a<numeric>(eb) &&
167 is_exactly_a<numeric>(ef.
subs(
x==12.34).
evalf())) {
175 return dynallocate<integral>(
x, ea, eb, ef);
184 if (is_a<numeric>(result))
186 throw logic_error(
"integrand does not evaluate to numeric");
210typedef map<error_and_integral, ex, error_and_integral_is_less>
lookup_map;
222 ex a = is_exactly_a<numeric>(a_in) ? a_in : a_in.
evalf();
223 ex b = is_exactly_a<numeric>(b_in) ? b_in : b_in.
evalf();
224 if(!is_exactly_a<numeric>(a) || !is_exactly_a<numeric>(b))
225 throw std::runtime_error(
"For numerical integration the boundaries of the integral should evalf into numbers.");
226 if(!is_exactly_a<numeric>(error))
227 throw std::runtime_error(
"For numerical integration the error should be a number.");
231 static symbol ivar(
"ivar");
234 if (emi!=lookup.end())
253 svec[i] = hvec[i]*(favec[i]+4*fcvec[i]+fbvec[i])/3;
255 errorvec[i] = error*
abs(svec[i]);
260 ex s1 = hvec[i]*(favec[i]+4*fd+fcvec[i])/6;
261 ex s2 = hvec[i]*(fcvec[i]+4*fe+fbvec[i])/6;
268 ex nu6 = max(errorvec[i],
abs(s1+s2)*error);
272 if (
abs(ex_to<numeric>(s1+s2-nu7)) <= nu6)
276 throw runtime_error(
"max integration level reached");
292 errorvec[i]=errorvec[i-1];
304 return ((
b-
a)*
f).degree(s);
309 return ((
b-
a)*
f).ldegree(s);
336 throw (std::out_of_range(
"integral::op() out of range"));
353 throw (std::out_of_range(
"integral::let_op() out of range"));
366 if (is_a<add>(newf)) {
368 v.reserve(newf.
nops());
369 for (
size_t i=0; i<newf.
nops(); ++i)
374 if (is_a<mul>(newf)) {
377 for (
size_t i=0; i<newf.
nops(); ++i)
381 prefactor *= newf.
op(i);
389 this->
setflag(status_flags::expanded);
393 const integral & newint = dynallocate<integral>(
x, newa, newb, newf);
402 throw(logic_error(
"differentiation with respect to dummy variable"));
426 return dynallocate<integral>(
x, conja, conjb, conjf);
436 if (is_a<power>(
f) &&
f.
op(0)==
x) {
Interface to GiNaC's sums of expressions.
Archiving of GiNaC expressions.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
const basic & setflag(unsigned f) const
Set some status_flags.
void ensure_if_modifiable() const
Ensure the object may be modified without hurting others, throws if this is not the case.
unsigned flags
of type status_flags
const basic & hold() const
Stop further evaluation.
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
Wrapper template for making GiNaC classes out of STL containers.
Lightweight wrapper for GiNaC's symbolic objects.
ex diff(const symbol &s, unsigned nth=1) const
Compute partial derivative of an expression.
ex expand(unsigned options=0) const
Expand an expression.
bool has(const ex &pattern, unsigned options=0) const
ex eval_ncmul(const exvector &v) const
unsigned return_type() const
return_type_t return_type_tinfo() const
ex subs(const exmap &m, unsigned options=0) const
int compare(const ex &other) const
void print(const print_context &c, unsigned level=0) const
Print expression to stream.
ex evalf() const override
Evaluate object numerically.
void do_print(const print_context &c, unsigned level) const
static ex relative_integration_error
ex expand(unsigned options=0) const override
Expand expression, i.e.
unsigned return_type() const override
int degree(const ex &s) const override
Return degree of highest power in object s.
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
size_t nops() const override
Number of operands/members.
ex conjugate() const override
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
ex eval_integ() const override
Evaluate integrals, if result is known.
ex eval_ncmul(const exvector &v) const override
int ldegree(const ex &s) const override
Return degree of lowest power in object s.
void do_print_latex(const print_latex &c, unsigned level) const
integral(const ex &x_, const ex &a_, const ex &b_, const ex &f_)
ex & let_op(size_t i) override
Return modifiable operand/member at position i.
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
ex op(size_t i) const override
Return operand/member at position i.
void archive(archive_node &n) const override
Save (a.k.a.
return_type_t return_type_tinfo() const override
static int max_integration_level
ex derivative(const symbol &s) const override
Default implementation of ex::diff().
This class holds a two-component object, a basis and and exponent representing exponentiation.
Base class for print_contexts.
Context for latex-parsable output.
@ expanded
.expand(0) has already done its job (other expand() options ignore this flag)
@ evaluated
.eval() has already done its job
Interface to GiNaC's initially known functions.
Interface to GiNaC's symbolic integral.
Interface to GiNaC's products of expressions.
bool haswild(const ex &x)
Check whether x has a wildcard anywhere as a subexpression.
ex adaptivesimpson(const ex &x, const ex &a_in, const ex &b_in, const ex &f, const ex &error)
Numeric integration routine based upon the "Adaptive Quadrature" one in "Numerical Analysis" by Burde...
B & dynallocate(Args &&... args)
Constructs a new (class basic or derived) B object on the heap.
const numeric abs(const numeric &x)
Absolute value.
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
print_func< print_dflt >(&diracone::do_print). print_func< print_latex >(&diracone
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(add, expairseq, print_func< print_context >(&add::do_print). print_func< print_latex >(&add::do_print_latex). print_func< print_csrc >(&add::do_print_csrc). print_func< print_tree >(&add::do_print_tree). print_func< print_python_repr >(&add::do_print_python_repr)) add
ex subsvalue(const ex &var, const ex &value, const ex &fun)
const numeric log(const numeric &x)
Natural logarithm.
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func< print_context >(&lst::do_print). print_func< print_tree >(&lst::do_print_tree)) template<> bool lst GINAC_BIND_UNARCHIVER(lst)
Specialization of container::info() for lst.
std::vector< ex > exvector
map< error_and_integral, ex, error_and_integral_is_less > lookup_map
Makes the interface to the underlying bignum package available.
Interface to GiNaC's overloaded operators.
Interface to GiNaC's symbolic exponentiation (basis^exponent).
GiNaC's class registrar (for class basic and all classes derived from it).
Interface to relations between expressions.
bool operator()(const error_and_integral &e1, const error_and_integral &e2) const
error_and_integral(const ex &err, const ex &integ)
To distinguish between different kinds of non-commutative objects.
Interface to GiNaC's symbolic objects.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...
Interface to GiNaC's wildcard objects.