SCalc
Public Member Functions
SCalc::Expression Class Reference

An expression ! More...

#include <expression.hh>

Inheritance diagram for SCalc::Expression:
Inheritance graph
[legend]
Collaboration diagram for SCalc::Expression:
Collaboration graph
[legend]

List of all members.

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 Expressionderive (int id)
 Derive an expression with regards to one variable.
virtual Expressioncopy ()
 Returns a freshly allocated copy of the expression.
virtual std::string pretty_print ()=0
 Pretty prints to a string.
virtual Expressionsimplify ()
 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 Expressionadd (Expression *, Expression *)
static Expressionsub (Expression *, Expression *)
static Expressionmul (Expression *, Expression *)
static Expressiondiv (Expression *, Expression *)

Detailed Description

An expression !

This class represents a valid expression. It is a pure virtual class, but all its descendants are internals of SCalc.


Member Function Documentation

virtual Expression* SCalc::Expression::derive ( int  id) [virtual]

Derive an expression with regards to one variable.

Parameters:
idthe 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.

See also:
simplify() SCalc::Session::varnames()
virtual void SCalc::Expression::dump ( ::std::ostream &  stream = ::std::cerr) [virtual]

Dumps the contents of the expression to a stream.

Used essentially for debugging.

Deprecated:
Not implemented everywhere. You'll have more luck with pretty_print().
virtual double SCalc::Expression::evaluate ( const double *  values,
const double *  s = NULL 
) [pure virtual]

Evaluate the expression.

Parameters:
valuesthe values of the indeterminates.
sinternal 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.

See also:
SCalc::Session::varnames()

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.

Parameters:
nbthe number of conditions
targetwhere the results will be stored
variablesarray 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.

See also:
evaluate()
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.

See also:
SCalc::Session::varnames()

The documentation for this class was generated from the following file: