AmpGen 2.1
Loading...
Searching...
No Matches
Expressions

Detailed Description

AmpGen Expressions are a set of classes for constructing functions from primatives such as the binary operators \((+,-,/,\times)\), and elementary functions such as trigonometric functions and sqrts. These are then compiled to conventional C++ at runtime, to allow fast and flexible evalulation of amplitudes. Expression trees can be built using overloaded operators, so

Expression x = a+b;

will given an expression that can calculate the sum of expressions a and b. There are constructors for expressions from constants and corresponding overloads of operators, so for example

Expression x = a+5;

generates a tree that adds '5' to the the tree 'a'.
Assorted optimisations will generally be invoked on the AST if constants are included, such as reduction of products and sums of constants.

There is limited functionality for expressions to be evaluated in-situ to the default values associated with their parameters, which can useful for debugging purposes. The more typical usage is to use an expression to generate a CompiledExpression that compiles the expression and wraps the corresponding shared library with a functor.

For unary functions, it is recommend to use the functions contained in the fcn:: namespace that have the same names as those in std::math. For example,

Expression y = fcn::sin(x);

Use of the unary classes directly can cause unexpected behaviour if used in conjunction with the auto keyword, and does not include some optimisations as readily such as constant folding.

Classes

class  AmpGen::Array
 Expression for a fixed size array of values. More...
 
class  AmpGen::ASTResolver
 (Internal) class to aide in the resolution of the dependencies of expression trees. More...
 
class  AmpGen::IExpression
 Virtual base class for other expression tree components. More...
 
class  AmpGen::Expression
 Wrapper class for shared_ptrs to virtual expressions for use in conjunction with operators to build expression trees. More...
 
class  AmpGen::Constant
 Class to contain a constant (which can contain a complex value) More...
 
class  AmpGen::Parameter
 Free parameter for expression. More...
 
class  AmpGen::LambdaExpression
 Parameter that the value of which is given by some arbitrary C++ function. More...
 
class  AmpGen::Ternary
 Evaluates the ternary operator. More...
 
struct  AmpGen::SubTree
 
class  AmpGen::ExpressionPack
 A group of expressions packed into a single expression. More...
 
class  AmpGen::IBinaryExpression
 Base class for binary expressions, i.e. More...
 
class  AmpGen::Sum
 Binary expression that returns \(l+r\). More...
 
class  AmpGen::Sub
 Binary expression that returns \(l-r\). More...
 
class  AmpGen::Product
 Binary expression that returns \(l\times r\). More...
 
class  AmpGen::Divide
 Binary expression that returns \(l / r\). More...
 
class  AmpGen::Pow
 Binary expression that returns \( l^{r} \). More...
 
class  AmpGen::Fmod
 Binary expression that returns the fractional part of \( l \mathrm{mod} r \). More...
 
class  AmpGen::LessThan
 Binary expression that returns \(l < r\). More...
 
class  AmpGen::GreaterThan
 Binary expression that returns \(l > r\). More...
 
class  AmpGen::LessThanEqualTo
 Binary expression that returns \(l < r\). More...
 
class  AmpGen::GreaterThanEqualTo
 Binary expression that returns \(l > r\). More...
 
class  AmpGen::And
 Binary expression that returns \(l \wedge r\). More...
 
class  AmpGen::Or
 Binary expression that returns \(l \wedge r\). More...
 
class  AmpGen::IUnaryExpression
 Base class for unary expressions, i.e. More...
 
class  AmpGen::Log
 Unary expression that returns \(\log(x)\). More...
 
class  AmpGen::Exp
 Unary expression that returns \(e^x\). More...
 
class  AmpGen::Sqrt
 Unary expression that returns \(\sqrt{x}\). More...
 
class  AmpGen::Abs
 Unary expression that returns \(|z|\). More...
 
class  AmpGen::Norm
 Unary expression that returns \(|z|^2\). More...
 
class  AmpGen::Conj
 Unary expression that returns \(z^{*}\). More...
 
class  AmpGen::Real
 Unary expression that returns the real part of \(z\). More...
 
class  AmpGen::Imag
 Unary expression that returns the imaginary part of \(z\). More...
 
class  AmpGen::Sin
 Unary expression that returns \(\sin(z)\). More...
 
class  AmpGen::Cos
 Unary expression that returns \(\cos(z)\). More...
 
class  AmpGen::Tan
 Unary expression that returns \(\tan(z)\). More...
 
class  AmpGen::ASin
 Unary expression that returns \(\sin^{-1}(z)\). More...
 
class  AmpGen::ACos
 Unary expression that returns \(\cos^{-1}(z)\). More...
 
class  AmpGen::ATan
 Unary expression that returns \(\tan^{-1}(z)\). More...
 
class  AmpGen::ISqrt
 Unary expression that uses inverse sqrt (faster than dividing by sqrt) More...
 
class  AmpGen::LGamma
 Unary expression that returns \(\log\left|\Gamma(x)\right|\). More...
 

Macros

#define ADD_DEBUG(X, Y)
 Make a (named) debugging expression and add to a set of DebugSymbols.
 
#define DEFINE_CAST(X)
 Define a cast from an expression implementation to the shared_ptr wrapper.
 
#define DECLARE_UNARY_OPERATOR(X)
 Macro to declare a unary operator, see IUnaryExpression.
 
#define DECLARE_BINARY_OPERATOR(X)
 Macro to declare a binary operator, see IBinaryExpression.
 

Macro Definition Documentation

◆ ADD_DEBUG

#define ADD_DEBUG ( X,
Y )
Value:
if ( Y != 0 ) Y->push_back( DebugSymbol( std::string( #X ), X ) ); \

Definition at line 41 of file Expression.h.

◆ DECLARE_BINARY_OPERATOR

#define DECLARE_BINARY_OPERATOR ( X)
Value:
class X : public IBinaryExpression { \
public: \
X( const Expression& l, const Expression& r ); \
X( const Expression& expr); \
virtual std::string to_string(const ASTResolver* resolver=nullptr) const override ; \
operator Expression() const ; \
virtual complex_t operator()() const override; \
}

Definition at line 80 of file Expression.h.

◆ DECLARE_UNARY_OPERATOR

#define DECLARE_UNARY_OPERATOR ( X)
Value:
class X : public IUnaryExpression { \
public: \
explicit X( const Expression& other ); \
virtual std::string to_string(const ASTResolver* resolver=nullptr) const override; \
virtual Expression d() const override; \
operator Expression() const; \
virtual complex_t operator()() const override; \
}

Definition at line 68 of file Expression.h.

◆ DEFINE_CAST

#define DEFINE_CAST ( X)
Value:
X::operator Expression() const \
{ return Expression( std::make_shared<X>( *this ) ); }

Definition at line 46 of file Expression.h.