SCalc::Expression Class Referenceabstract

An expression ! More...

`#include <expression.hh>`

Inheritance diagram for SCalc::Expression:
[legend]
Collaboration diagram for SCalc::Expression:
[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 Expression * | derive (int id)
| Derive an expression with regards to one variable. More...
virtual Expression * | copy ()
| Returns a freshly allocated copy of the expression.
virtual std::string | pretty_print ()=0
| Pretty prints to a string. More...
virtual Expression * | simplify ()
| 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:
Session * | session ()
| The SCalc::Session object used. More...
Expression * | to_expression ()
| Converts to SCalc::Expression. More...
virtual int | is_syntax_error ()
| Is it a SCalc::SyntaxError ? More...
SyntaxError * | to_syntax_error ()
| Converts to SCalc::SyntaxError. More...
virtual int | is_func_def ()
| Is it a SCalc::FuncDef ? More...
FuncDef * | to_func_def ()
| Converts to SCalc::FuncDef. More...
virtual int | can_delete ()

## 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 *)

## 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

  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.

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

  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.

See also
  SCalc::Session::varnames()

Referenced by SCalc::ExprFunc::evaluate().

## is_null()

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

## is_valid()

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 !

## mass_evaluate()

virtual double* SCalc::Expression::mass_evaluate | ( | int | nb,
|  | double * | target,
|  | const double ** | variables
| ) |  |

virtual

Evaluates the Expression for different parameters.

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.

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

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

## used_variables()

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:

- lib/expression.hh