This is a tutorial that documents GiNaC @value{VERSION}, an open
framework for symbolic computation within the C++ programming language.
-Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany
+Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@page
@vskip 0pt plus 1filll
-Copyright @copyright{} 1999-2015 Johannes Gutenberg University Mainz, Germany
+Copyright @copyright{} 1999-2016 Johannes Gutenberg University Mainz, Germany
@sp 2
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@section License
The GiNaC framework for symbolic computation within the C++ programming
-language is Copyright @copyright{} 1999-2015 Johannes Gutenberg
+language is Copyright @copyright{} 1999-2016 Johannes Gutenberg
University Mainz, Germany.
This program is free software; you can redistribute it and/or
@uref{http://pkg-config.freedesktop.org}.
Last but not least, the CLN library
is used extensively and needs to be installed on your system.
-Please get it from @uref{ftp://ftpthep.physik.uni-mainz.de/pub/gnu/}
-(it is covered by GPL) and install it prior to trying to install
-GiNaC. The configure script checks if it can find it and if it cannot
-it will refuse to continue.
+Please get it from @uref{http://www.ginac.de/CLN/} (it is licensed under
+the GPL) and install it prior to trying to install GiNaC. The configure
+script checks if it can find it and if it cannot, it will refuse to
+continue.
@node Configuration, Building GiNaC, Prerequisites, Installation
Internally, the anonymous evaluator in GiNaC is implemented by the methods
@example
-ex ex::eval(int level = 0) const;
-ex basic::eval(int level = 0) const;
+ex ex::eval() const;
+ex basic::eval() const;
@end example
but unless you are extending GiNaC with your own classes or functions, there
creates a matrix with @samp{r} rows and @samp{c} columns with all elements
set to zero.
-The fastest way to create a matrix with preinitialized elements is to assign
-a list of comma-separated expressions to an empty matrix (see below for an
-example). But you can also specify the elements as a (flat) list with
+The easiest way to create a matrix is using an initializer list of
+initializer lists, all of the same size:
+
+@example
+@{
+ matrix m = @{@{1, -a@},
+ @{a, 1@}@};
+@}
+@end example
+
+You can also specify the elements as a (flat) list with
@example
matrix::matrix(unsigned r, unsigned c, const lst & l);
@cindex @code{symbolic_matrix()}
@example
ex diag_matrix(const lst & l);
+ex diag_matrix(initializer_list<ex> l);
ex unit_matrix(unsigned x);
ex unit_matrix(unsigned r, unsigned c);
ex symbolic_matrix(unsigned r, unsigned c, const string & base_name);
const string & tex_base_name);
@end example
-@code{diag_matrix()} constructs a diagonal matrix given the list of diagonal
+@code{diag_matrix()} constructs a square diagonal matrix given the diagonal
elements. @code{unit_matrix()} creates an @samp{x} by @samp{x} (or @samp{r}
by @samp{c}) unit matrix. And finally, @code{symbolic_matrix} constructs a
matrix filled with newly generated symbols made of the specified base name
@example
@{
- matrix m(3,3);
- m = 11, 12, 13,
- 21, 22, 23,
- 31, 32, 33;
+ matrix m = @{@{11, 12, 13@},
+ @{21, 22, 23@},
+ @{31, 32, 33@}@};
cout << reduced_matrix(m, 1, 1) << endl;
// -> [[11,13],[31,33]]
cout << sub_matrix(m, 1, 2, 1, 2) << endl;
@{
symbol a("a"), b("b");
- matrix M(2, 2);
- M = a, 0,
- 0, b;
+ matrix M = @{@{a, 0@},
+ @{0, b@}@};
cout << M << endl;
// -> [[a,0],[0,b]]
@example
@{
- matrix A(2, 2), B(2, 2), C(2, 2);
- A = 1, 2,
- 3, 4;
- B = -1, 0,
- 2, 1;
- C = 8, 4,
- 2, 1;
+ matrix A = @{@{ 1, 2@},
+ @{ 3, 4@}@};
+ matrix B = @{@{-1, 0@},
+ @{ 2, 1@}@};
+ matrix C = @{@{ 8, 4@},
+ @{ 2, 1@}@};
matrix result = A.mul(B).sub(C.mul_scalar(2));
cout << result << endl;
symbol x("x"), y("y");
// A is a 2x2 matrix, X is a 2x1 vector
- matrix A(2, 2), X(2, 1);
- A = 1, 2,
- 3, 4;
- X = x, y;
+ matrix A = @{@{1, 2@},
+ @{3, 4@}@};
+ matrix X = @{@{x, y@}@};
cout << indexed(A, i, i) << endl;
// -> 5
something very close to @code{dirac_gamma(mu)}, although
@code{dirac_gamma} have more efficient simplification mechanism.
@cindex @code{get_metric()}
+Also, the object created by @code{clifford_unit(mu, minkmetric())} is
+not aware about the symmetry of its metric, see the start of the pevious
+paragraph. A more accurate analog of 'dirac_gamma(mu)' should be
+specifies as follows:
+
+@example
+ clifford_unit(mu, indexed(minkmetric(),sy_symm(),varidx(symbol("i"),4),varidx(symbol("j"),4)));
+@end example
+
The method @code{clifford::get_metric()} returns a metric defining this
Clifford number.
...
idx i(symbol("i"), 4);
realsymbol s("s");
- ex M = diag_matrix(lst@{1, -1, 0, s@});
+ ex M = diag_matrix(@{1, -1, 0, s@});
ex e0 = lst_to_clifford(lst@{1, 0, 0, 0@}, i, M);
ex e1 = lst_to_clifford(lst@{0, 1, 0, 0@}, i, M);
ex e2 = lst_to_clifford(lst@{0, 0, 1, 0@}, i, M);
@tab @dots{}a polynomial with (possibly complex) rational coefficients (such as @math{2/3+7/2*I})
@item @code{rational_function}
@tab @dots{}a rational function (@math{x+y}, @math{z/(x+y)})
-@item @code{algebraic}
-@tab @dots{}an algebraic object (@math{sqrt(2)}, @math{sqrt(x)-1})
@end multitable
@end cartouche
predicates to the STL:
@example
-class ex_is_less : public std::binary_function<ex, ex, bool> @{
+class ex_is_less @{
public:
bool operator()(const ex &lh, const ex &rh) const;
@};
-class ex_is_equal : public std::binary_function<ex, ex, bool> @{
+class ex_is_equal @{
public:
bool operator()(const ex &lh, const ex &rh) const;
@};
// count the number of expressions equal to '1'
unsigned num_ones = std::count_if(v.begin(), v.end(),
- std::bind2nd(ex_is_equal(), 1));
+ [](const ex& e) @{ return ex_is_equal()(e, 1); @});
@end example
The implementation of @code{ex_is_less} uses the member function
To evaluate them using floating-point arithmetic you need to call
@example
-ex ex::evalf(int level = 0) const;
+ex ex::evalf() const;
@end example
@cindex @code{Digits}
@{
...
public:
- ex eval(int level = 0) const;
+ ex eval() const override;
...
@};
-ex mystring::eval(int level) const
+ex mystring::eval() const
@{
string new_str;
for (size_t i=0; i<str.length(); i++) @{
if (new_str.length() == 0)
return 0;
- else
- return mystring(new_str).hold();
+
+ return mystring(new_str).hold();
@}
@end example
-The @code{level} argument is used to limit the recursion depth of the
-evaluation. We don't have any subexpressions in the @code{mystring}
-class so we are not concerned with this. If we had, we would call the
-@code{eval()} functions of the subexpressions with @code{level - 1} as
-the argument if @code{level != 1}. The @code{hold()} member function
-sets a flag in the object that prevents further evaluation. Otherwise
-we might end up in an endless loop. When you want to return the object
-unmodified, use @code{return this->hold();}.
+The @code{hold()} member function sets a flag in the object that prevents
+further evaluation. Otherwise we might end up in an endless loop. When you
+want to return the object unmodified, use @code{return this->hold();}.
+
+If our class had subobjects, we would have to evaluate them first (unless
+they are all of type @code{ex}, which are automatically evaluated). We don't
+have any subexpressions in the @code{mystring} class, so we are not concerned
+with this.
Let's confirm that it works:
@cindex @code{calchash()}
@cindex @code{is_equal_same_type()}
@example
-unsigned calchash() const;
-bool is_equal_same_type(const basic & other) const;
+unsigned calchash() const override;
+bool is_equal_same_type(const basic & other) const override;
@end example
The @code{calchash()} method returns an @code{unsigned} hash value for the
might want to provide:
@example
-bool info(unsigned inf) const;
-ex evalf(int level = 0) const;
-ex series(const relational & r, int order, unsigned options = 0) const;
-ex derivative(const symbol & s) const;
+bool info(unsigned inf) const override;
+ex evalf() const override;
+ex series(const relational & r, int order, unsigned options = 0) const override;
+ex derivative(const symbol & s) const override;
@end example
If your class stores sub-expressions (see the scalar product example in the
@cindex @code{let_op()}
@example
-size_t nops() cont;
-ex op(size_t i) const;
-ex & let_op(size_t i);
-ex subs(const lst & ls, const lst & lr, unsigned options = 0) const;
-ex map(map_function & f) const;
+size_t nops() const override;
+ex op(size_t i) const override;
+ex & let_op(size_t i) override;
+ex subs(const lst & ls, const lst & lr, unsigned options = 0) const override;
+ex map(map_function & f) const override;
@end example
@code{let_op()} is a variant of @code{op()} that allows write access. The