SCalc
Public Member Functions | List of all members
SCalc::Expression Class Referenceabstract

An expression ! More...

#include <expression.hh>

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

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. More...
 
virtual void dump (::std::ostream &stream=::std::cerr)
 Dumps the contents of the expression to a stream. More...
 
virtual std::set< int > used_variables ()
 Variable used by an expression. More...
 
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. More...
 
virtual Expressioncopy ()
 Returns a freshly allocated copy of the expression.
 
virtual std::string pretty_print ()=0
 Pretty prints to a string. More...
 
virtual Expressionsimplify ()
 Simplifies the expression. More...
 
virtual double * mass_evaluate (int nb, double *target, const double **variables)
 Evaluates the Expression for different parameters. More...
 
- Public Member Functions inherited from SCalc::ParserResult
 ParserResult (Session *s)
 Constructors/desctructors:
 
Sessionsession ()
 The SCalc::Session object used. More...
 
virtual int can_delete ()
 
Expressionto_expression ()
 Converts to SCalc::Expression. More...
 
virtual int is_syntax_error ()
 Is it a SCalc::SyntaxError ? More...
 
SyntaxErrorto_syntax_error ()
 Converts to SCalc::SyntaxError. More...
 
virtual int is_func_def ()
 Is it a SCalc::FuncDef ? More...
 
FuncDefto_func_def ()
 Converts to SCalc::FuncDef. More...
 

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

◆ derive()

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()

◆ dump()

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().

◆ evaluate()

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().

◆ is_null()

virtual int SCalc::Expression::is_null ( )
inlinevirtual

If Null, then the value is zero... Will be used for simplification, when I get to that point...

◆ is_valid()

virtual int SCalc::Expression::is_valid ( )
inlinevirtual

True if no syntax errors. When looking for the result of an eval, always look for this !

◆ mass_evaluate()

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()

◆ pretty_print()

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.

◆ simplify()

virtual Expression* SCalc::Expression::simplify ( )
inlinevirtual

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.

◆ used_variables()

virtual std::set<int> SCalc::Expression::used_variables ( )
inlinevirtual

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: