X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=doc%2Ftutorial%2Fginac.texi;h=4f7e4b0f3dde87641348db9b2a460db293249573;hp=0d86eeee4d673b48d20c210989cb3a498165b802;hb=47295e1e73d54bf6cf8953ecc0ce2a848c1fb5b3;hpb=c6ead0d1f88d99b0d8cc99b2da8ef9e9c41a073f diff --git a/doc/tutorial/ginac.texi b/doc/tutorial/ginac.texi index 0d86eeee..4f7e4b0f 100644 --- a/doc/tutorial/ginac.texi +++ b/doc/tutorial/ginac.texi @@ -838,8 +838,8 @@ some immediate simplifications. 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 @@ -3969,8 +3969,6 @@ table: @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 @@ -8241,11 +8239,11 @@ class mystring : public basic @{ ... 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; ihold();}. +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: @@ -8293,8 +8291,8 @@ required but will make operations with objects of the class more efficient: @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 @@ -8315,10 +8313,10 @@ For a real algebraic class, there are probably some more functions that you 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(int level = 0) 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 @@ -8326,11 +8324,11 @@ previous section) you will probably want to override @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