manpagez: man pages & more
info ginac
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.4 Pattern matching and advanced substitutions

GiNaC allows the use of patterns for checking whether an expression is of a certain form or contains subexpressions of a certain form, and for substituting expressions in a more general way.

A pattern is an algebraic expression that optionally contains wildcards. A wildcard is a special kind of object (of class wildcard) that represents an arbitrary expression. Every wildcard has a label which is an unsigned integer number to allow having multiple different wildcards in a pattern. Wildcards are printed as ‘$label’ (this is also the way they are specified in ginsh). In C++ code, wildcard objects are created with the call

 
ex wild(unsigned label = 0);

which is simply a wrapper for the wildcard() constructor with a shorter name.

Some examples for patterns:

Constructed as

Output as

wild()

$0

pow(x,wild())

x^$0

atan2(wild(1),wild(2))

atan2($1,$2)

indexed(A,idx(wild(),3))

A.$0

Notes:


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.