static ex stieltjes1_evalf(const ex& x, PyObject* parent) { if (is_exactly_a<numeric>(x)) { try { return stieltjes(ex_to<numeric>(x.evalf(0, parent))); } catch (const dunno &e) { } } return stieltjes(x).hold(); }
static ex stieltjes1_eval(const ex& arg) { if (not arg.info(info_flags::numeric)) return stieltjes(arg).hold(); if (not arg.info(info_flags::integer)) return stieltjes(ex_to<numeric>(arg)); if (ex_to<numeric>(arg).is_zero()) return Euler; else if (not ex_to<numeric>(arg).is_negative()) return stieltjes(arg).hold(); else throw std::runtime_error("Stieltjes constant of negative index"); }
bool Stokhos::StieltjesPCEBasis<ordinal_type, value_type>:: computeRecurrenceCoefficients(ordinal_type n, Teuchos::Array<value_type>& alpha, Teuchos::Array<value_type>& beta, Teuchos::Array<value_type>& delta, Teuchos::Array<value_type>& gamma) const { ordinal_type nqp = phi_vals.size(); Teuchos::Array<value_type> nrm(n); Teuchos::Array< Teuchos::Array<value_type> > vals(nqp); for (ordinal_type i=0; i<nqp; i++) vals[i].resize(n); stieltjes(0, n, pce_weights, pce_vals, alpha, beta, nrm, vals); for (ordinal_type i=0; i<n; i++) { delta[i] = value_type(1.0); gamma[i] = value_type(1.0); } // Save basis functions at quad point values if (n == this->p+1) phi_vals = vals; return false; }
static ex zeta1_series(const ex& m, const relational& rel, int order, unsigned options) { // use taylor expansion everywhere except at the singularity at 1 const numeric val = ex_to<numeric>(m.subs(rel, subs_options::no_pattern)); if (val != 1) throw do_taylor(); // caught by function::series() // at 1, use the expansion with the stieltjes-constants ex ser = 1/(m-1); numeric fac = 1; for (int n = 0; n <= order; ++n) { fac = fac.mul(n+1); ser += pow(-1, n) * stieltjes(n) * pow(m-1, n) * fac.inverse(); } return ser.series(rel, order, options); }
void Stokhos::StieltjesPCEBasis<ordinal_type, value_type>:: computeRecurrenceCoefficients(ordinal_type n, Teuchos::Array<value_type>& alpha, Teuchos::Array<value_type>& beta, Teuchos::Array<value_type>& delta) const { ordinal_type nqp = phi_vals.size(); Teuchos::Array<value_type> nrm(n); Teuchos::Array< Teuchos::Array<value_type> > vals(nqp); for (ordinal_type i=0; i<nqp; i++) vals[i].resize(n); stieltjes(0, n, pce_weights, pce_vals, alpha, beta, nrm, vals); for (ordinal_type i=0; i<n; i++) delta[i] = value_type(1.0); }
Stokhos::StieltjesPCEBasis<ordinal_type, value_type>:: StieltjesPCEBasis( ordinal_type p, const Teuchos::RCP<const Stokhos::OrthogPolyApprox<ordinal_type, value_type> >& pce_, const Teuchos::RCP<const Stokhos::Quadrature<ordinal_type, value_type> >& quad_, bool use_pce_quad_points_, bool normalize, bool project_integrals_, const Teuchos::RCP<const Stokhos::Sparse3Tensor<ordinal_type, value_type> >& Cijk_) : RecurrenceBasis<ordinal_type, value_type>("Stieltjes PCE", p, normalize), pce(pce_), quad(quad_), pce_weights(quad->getQuadWeights()), basis_values(quad->getBasisAtQuadPoints()), pce_vals(), phi_vals(), use_pce_quad_points(use_pce_quad_points_), fromStieltjesMat(p+1,pce->size()), project_integrals(project_integrals_), basis(pce->basis()), Cijk(Cijk_), phi_pce_coeffs() { // Evaluate PCE at quad points const Teuchos::Array< Teuchos::Array<value_type> >& quad_points = quad->getQuadPoints(); ordinal_type nqp = pce_weights.size(); pce_vals.resize(nqp); phi_vals.resize(nqp); for (ordinal_type i=0; i<nqp; i++) { pce_vals[i] = pce->evaluate(quad_points[i], basis_values[i]); phi_vals[i].resize(p+1); } if (project_integrals) phi_pce_coeffs.resize(basis->size()); // Compute coefficients via Stieltjes stieltjes(0, p+1, pce_weights, pce_vals, this->alpha, this->beta, this->norms, phi_vals); for (ordinal_type i=0; i<=p; i++) this->delta[i] = value_type(1.0); ordinal_type sz = pce->size(); fromStieltjesMat.putScalar(0.0); for (ordinal_type i=0; i<=p; i++) { for (ordinal_type j=0; j<sz; j++) { for (ordinal_type k=0; k<nqp; k++) fromStieltjesMat(i,j) += pce_weights[k]*phi_vals[k][i]*basis_values[k][j]; fromStieltjesMat(i,j) /= basis->norm_squared(j); } } // Setup rest of recurrence basis //this->setup(); this->gamma[0] = value_type(1); for (ordinal_type k=1; k<=p; k++) { this->gamma[k] = value_type(1); } //If you want normalized polynomials, set gamma and reset the norms to 1. if( normalize ) { for (ordinal_type k=0; k<=p; k++) { this->gamma[k] = value_type(1)/std::sqrt(this->norms[k]); this->norms[k] = value_type(1); } } }