SCalc
|
An expression ! More...
#include <expression.hh>
Public Member Functions | |
Expression (Session *s) | |
virtual int | is_expression () |
Yes, this is an expression: | |
virtual double | evaluate (const double *values, const double *s=NULL)=0 |
Evaluate the expression. | |
virtual void | dump (::std::ostream &stream=::std::cerr) |
Dumps the contents of the expression to a stream. | |
virtual std::set< int > | used_variables () |
Variable used by an expression. | |
int | evaluable () |
Tells if this expression can be evaluated. | |
double | evaluate () |
If it can be evaluated, returns the given value. | |
virtual int | is_null () |
virtual int | is_id () |
If Id, then the value is always 1. | |
virtual int | is_const () |
If const, then the value is always 1. | |
virtual int | is_valid () |
virtual Expression * | derive (int id) |
Derive an expression with regards to one variable. | |
virtual Expression * | copy () |
Returns a freshly allocated copy of the expression. | |
virtual std::string | pretty_print ()=0 |
Pretty prints to a string. | |
virtual Expression * | simplify () |
Simplifies the expression. | |
virtual double * | mass_evaluate (int nb, double *target, const double **variables) |
Evaluates the Expression for different parameters. | |
Static Public Member Functions | |
Operations on expressions | |
A set of function to manipulate expressions algebraically. All these functions take ownership of the arguments you give them, and those will be freed when you free the result. | |
static Expression * | add (Expression *, Expression *) |
static Expression * | sub (Expression *, Expression *) |
static Expression * | mul (Expression *, Expression *) |
static Expression * | div (Expression *, Expression *) |
An expression !
This class represents a valid expression. It is a pure virtual class, but all its descendants are internals of SCalc.
virtual Expression* SCalc::Expression::derive | ( | int | id | ) | [virtual] |
Derive an expression with regards to one variable.
id | the index of the variable by which we'll derive |
Returns a new Expression containing the derivative of the expression with regard to variable number id. You are responsible for taking care of freeing the result if necessary. You might want to simplify() the returned expression, as this is not done by default.
virtual void SCalc::Expression::dump | ( | ::std::ostream & | stream = ::std::cerr | ) | [virtual] |
Dumps the contents of the expression to a stream.
Used essentially for debugging.
virtual double SCalc::Expression::evaluate | ( | const double * | values, |
const double * | s = NULL |
||
) | [pure virtual] |
Evaluate the expression.
values | the values of the indeterminates. |
s | internal parameter. |
This function evaluates the expression using values for the values of the indeterminates. The second parameter is only used internally, you should never need it.
values is an array of variable values. You can get their name with the SCalc::Session::varnames() function. This way, you can setup the correspondance only once for a whole vector.
Referenced by SCalc::ExprFunc::evaluate().
virtual int SCalc::Expression::is_null | ( | ) | [inline, virtual] |
If Null, then the value is zero... Will be used for simplification, when I get to that point...
virtual int SCalc::Expression::is_valid | ( | ) | [inline, virtual] |
True if no syntax errors. When looking for the result of an eval, always look for this !
virtual double* SCalc::Expression::mass_evaluate | ( | int | nb, |
double * | target, | ||
const double ** | variables | ||
) | [virtual] |
Evaluates the Expression for different parameters.
nb | the number of conditions |
target | where the results will be stored |
variables | array of pointers to arrays storing the conditions |
This function evaluates the expression nb times for the conditions given in variables. The results are stored in target.
virtual std::string SCalc::Expression::pretty_print | ( | ) | [pure virtual] |
Pretty prints to a string.
Pretty-prints the expression to a string. Does not attempt to simplify anything.
Implements SCalc::ParserResult.
virtual Expression* SCalc::Expression::simplify | ( | ) | [inline, virtual] |
Simplifies the expression.
Returns a copy of the expression with small simplifications performed. The simplification engine is very basic for now. It detects only some pretty obvious simplifications.
The returned value is a fresh copy that should be deleted when not used anymore.
References copy().
virtual std::set<int> SCalc::Expression::used_variables | ( | ) | [inline, virtual] |
Variable used by an expression.
Returns a set containing the index of each variable used by the expression.