muParserScripting.h
Go to the documentation of this file.
/***************************************************************************
File : muParserScripting.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2006 by Ion Vasilief, Knut Franke
Email (use @ for *) : ion_vasilief*yahoo.fr, knut.franke*gmx.de
Description : Evaluate mathematical expressions using muParser
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef MUPARSER_SCRIPTING_H
#define MUPARSER_SCRIPTING_H
#include "ScriptingEnv.h"
#include "Script.h"
#include "muParserScript.h"
#include <muParser.h>
#include "math.h"
#include <gsl/gsl_sf.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>
class muParserScripting: public ScriptingEnv
{
Q_OBJECT
public:
static const char *langName;
muParserScripting(ApplicationWindow *parent) : ScriptingEnv(parent, langName){
d_initialized = true;
gsl_set_error_handler_off();
}
static ScriptingEnv *constructor(ApplicationWindow *parent) { return new muParserScripting(parent); }
bool isRunning() const { return true; }
Script *newScript(const QString &code, QObject *context, const QString &name="<input>")
{
return new muParserScript(this, code, context, name);
}
// we do not support global variables
bool setQObject(QObject*, const char*) { return false; }
bool setInt(int, const char*) { return false; }
bool setDouble(double, const char*) { return false; }
const QStringList mathFunctions() const;
const QString mathFunctionDoc (const QString &name) const;
const static QStringList functionsList(bool tableContext = false);
const static QString explainFunction(const QString &name);
struct mathFunction
{
char *name;
int numargs;
double (*fun1)(double);
double (*fun2)(double,double);
double (*fun3)(double,double,double);
QString description;
};
static const mathFunction math_functions[];
private:
static double rnd(double x){
gsl_rng_default_seed = (unsigned int)x*time(NULL);
const gsl_rng_type * T = gsl_rng_default;
gsl_rng * r = gsl_rng_alloc (T);
double u = gsl_rng_uniform (r);
gsl_rng_free (r);
return u;
}
static double normal(double x){
const gsl_rng_type * T = gsl_rng_default;
gsl_rng * r = gsl_rng_alloc (T);
if (!r)
return 0.0;
gsl_rng_set(r, (unsigned int)x*time(NULL));
double u = gsl_ran_ugaussian(r);
gsl_rng_free (r);
return u;
}
static double mod(double x, double y){ return fmod(x,y);};
static double bessel_I0(double x){ return gsl_sf_bessel_I0 (x);};
static double bessel_I1(double x){ return gsl_sf_bessel_I1 (x);};
static double bessel_In(double x, double n){ return gsl_sf_bessel_In ((int)n, x);};
static double bessel_J0(double x){ return gsl_sf_bessel_J0 (x);};
static double bessel_J1(double x){ return gsl_sf_bessel_J1 (x);};
static double bessel_Jn(double x, double n){ return gsl_sf_bessel_Jn ((int)n, x);};
static double bessel_Yn(double x, double n){ return gsl_sf_bessel_Yn ((int)n, x);};
static double bessel_Jn_zero(double n, double s){ return gsl_sf_bessel_zero_Jnu(n, (unsigned int) s);};
static double bessel_Y0(double x){ return gsl_sf_bessel_Y0 (x);};
static double bessel_Y1(double x){ return gsl_sf_bessel_Y1 (x);};
static double beta(double a, double b){ return gsl_sf_beta (a,b);};
static double erf(double x){ return gsl_sf_erf (x);};
static double erfc(double x){ return gsl_sf_erfc (x);};
static double erf_Z(double x){ return gsl_sf_erf_Z (x);};
static double erf_Q(double x){ return gsl_sf_erf_Q (x);};
static double gamma(double x){ return gsl_sf_gamma (x);};
static double lngamma(double x){ return gsl_sf_lngamma (x);};
static double hazard(double x){ return gsl_sf_hazard (x);};
static double lambert_W0(double x){ return gsl_sf_lambert_W0(x);};
static double lambert_Wm1(double x){ return gsl_sf_lambert_Wm1(x);};
static double invt(double x, double n){ return gsl_cdf_tdist_P(x, n);};
static double ttable(double x, double n){ return gsl_cdf_tdist_Pinv(x, n);};
static double ftable(double x, double m, double n){return gsl_cdf_fdist_Pinv(x, m, n);};
static double invf(double x, double m, double n){return gsl_cdf_fdist_P(x, m, n);};
static double gauss_pdf(double x, double sigma){return gsl_ran_gaussian_pdf (x, sigma);};
static double gauss_cdf(double x, double sigma){return gsl_cdf_gaussian_P (x, sigma);};
static double inv_gauss_cdf(double x, double sigma){return gsl_cdf_gaussian_Pinv(x, sigma);};
static double normcdf(double x){return gsl_cdf_ugaussian_P(x);};
static double norminv(double x){return gsl_cdf_ugaussian_Pinv(x);};
static double chi2cdf(double x, double n){return gsl_cdf_chisq_P (x, n);};
static double chi2inv(double x, double n){return gsl_cdf_chisq_Pinv(x, n);};
static double dilog(double x){return gsl_sf_dilog(x);};
};
class EmptySourceError : public mu::ParserError
{
public:
EmptySourceError() {}
};
#endif
muParserScripting::setQObject
bool setQObject(QObject *, const char *)
Definition: muParserScripting.h:64
muParserScripting::hazard
static double hazard(double x)
Definition: muParserScripting.h:124
muParserScripting::chi2cdf
static double chi2cdf(double x, double n)
Definition: muParserScripting.h:136
muParserScripting::erfc
static double erfc(double x)
Definition: muParserScripting.h:119
muParserScripting::isRunning
bool isRunning() const
whether asynchronuous execution is enabled (if supported by the implementation)
Definition: muParserScripting.h:57
muParserScripting::bessel_Jn_zero
static double bessel_Jn_zero(double n, double s)
Definition: muParserScripting.h:114
muParserScripting::lambert_Wm1
static double lambert_Wm1(double x)
Definition: muParserScripting.h:126
muParserScripting::setDouble
bool setDouble(double, const char *)
Definition: muParserScripting.h:66
muParserScripting::muParserScripting
muParserScripting(ApplicationWindow *parent)
Definition: muParserScripting.h:51
muParserScripting::erf_Z
static double erf_Z(double x)
Definition: muParserScripting.h:120
muParserScripting::mathFunction
Definition: muParserScripting.h:74
EmptySourceError::EmptySourceError
EmptySourceError()
Definition: muParserScripting.h:144
muParserScripting::normal
static double normal(double x)
Definition: muParserScripting.h:95
muParserScripting::mathFunctionDoc
const QString mathFunctionDoc(const QString &name) const
Return a documentation string for the given mathematical function.
Definition: muParserScripting.cpp:113
muParserScripting::explainFunction
static const QString explainFunction(const QString &name)
Definition: muParserScripting.cpp:134
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
ScriptingEnv.h
muParserScripting::bessel_Jn
static double bessel_Jn(double x, double n)
Definition: muParserScripting.h:112
muParserScripting::mathFunction::fun1
double(* fun1)(double)
Definition: muParserScripting.h:78
muParserScripting::bessel_In
static double bessel_In(double x, double n)
Definition: muParserScripting.h:109
muParserScripting::dilog
static double dilog(double x)
Definition: muParserScripting.h:138
muParserScripting::bessel_Y1
static double bessel_Y1(double x)
Definition: muParserScripting.h:116
muParserScript
TODO.
Definition: muParserScript.h:42
Script.h
muParserScripting::mathFunction::fun3
double(* fun3)(double, double, double)
Definition: muParserScripting.h:80
muParserScripting::mathFunction::numargs
int numargs
Definition: muParserScripting.h:77
muParserScripting::bessel_I0
static double bessel_I0(double x)
Definition: muParserScripting.h:107
muParserScripting::rnd
static double rnd(double x)
Definition: muParserScripting.h:86
muParserScripting::invf
static double invf(double x, double m, double n)
Definition: muParserScripting.h:130
Script
A chunk of scripting code. Abstract.
Definition: Script.h:50
muParserScripting::beta
static double beta(double a, double b)
Definition: muParserScripting.h:117
muParserScripting::setInt
bool setInt(int, const char *)
Definition: muParserScripting.h:65
muParserScripting
TODO.
Definition: muParserScripting.h:45
muParserScripting::erf_Q
static double erf_Q(double x)
Definition: muParserScripting.h:121
muParserScripting::mathFunctions
const QStringList mathFunctions() const
Return a list of supported mathematical functions. These should be imported into the global namespace...
Definition: muParserScripting.cpp:108
muParserScripting::invt
static double invt(double x, double n)
Definition: muParserScripting.h:127
muParserScripting::bessel_Y0
static double bessel_Y0(double x)
Definition: muParserScripting.h:115
muParserScripting::normcdf
static double normcdf(double x)
Definition: muParserScripting.h:134
muParserScripting::langName
static const char * langName
Definition: muParserScripting.h:50
ApplicationWindow
QtiPlot&#39;s main window.
Definition: ApplicationWindow.h:133
muParserScripting::math_functions
static const mathFunction math_functions[]
Definition: muParserScripting.h:83
muParserScripting::mathFunction::fun2
double(* fun2)(double, double)
Definition: muParserScripting.h:79
muParserScripting::ftable
static double ftable(double x, double m, double n)
Definition: muParserScripting.h:129
muParserScripting::bessel_J0
static double bessel_J0(double x)
Definition: muParserScripting.h:110
ScriptingEnv::d_initialized
bool d_initialized
whether the interpreter has been successfully initialized
Definition: ScriptingEnv.h:106
muParserScript.h
EmptySourceError
Definition: muParserScripting.h:141
muParserScripting::bessel_I1
static double bessel_I1(double x)
Definition: muParserScripting.h:108
muParserScripting::inv_gauss_cdf
static double inv_gauss_cdf(double x, double sigma)
Definition: muParserScripting.h:133
muParserScripting::gauss_pdf
static double gauss_pdf(double x, double sigma)
Definition: muParserScripting.h:131
muParserScripting::bessel_Yn
static double bessel_Yn(double x, double n)
Definition: muParserScripting.h:113
muParserScripting::norminv
static double norminv(double x)
Definition: muParserScripting.h:135
muParserScripting::erf
static double erf(double x)
Definition: muParserScripting.h:118
muParserScripting::lngamma
static double lngamma(double x)
Definition: muParserScripting.h:123
muParserScripting::lambert_W0
static double lambert_W0(double x)
Definition: muParserScripting.h:125
muParserScripting::gauss_cdf
static double gauss_cdf(double x, double sigma)
Definition: muParserScripting.h:132
muParserScripting::ttable
static double ttable(double x, double n)
Definition: muParserScripting.h:128
muParserScripting::gamma
static double gamma(double x)
Definition: muParserScripting.h:122
muParserScripting::mod
static double mod(double x, double y)
Definition: muParserScripting.h:106
muParserScripting::constructor
static ScriptingEnv * constructor(ApplicationWindow *parent)
Definition: muParserScripting.h:55
muParserScripting::mathFunction::name
char * name
Definition: muParserScripting.h:76
muParserScripting::newScript
Script * newScript(const QString &code, QObject *context, const QString &name="<input>")
Instantiate the Script subclass matching the ScriptEnv subclass.
Definition: muParserScripting.h:58
muParserScripting::chi2inv
static double chi2inv(double x, double n)
Definition: muParserScripting.h:137
muParserScripting::mathFunction::description
QString description
Definition: muParserScripting.h:81
muParserScripting::functionsList
static const QStringList functionsList(bool tableContext=false)
Definition: muParserScripting.cpp:118
muParserScripting::bessel_J1
static double bessel_J1(double x)
Definition: muParserScripting.h:111