From: Vladimir V. Kisil Date: Sun, 8 Aug 2021 14:18:31 +0000 (+0200) Subject: Add method relational::canonical(). X-Git-Tag: release_1-8-1~1 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=cb1ab077ba8ef330a75f40cf78b21fabbb35fb62 Add method relational::canonical(). It returns an equivalent relation with the zero right-hand side. --- diff --git a/doc/tutorial/ginac.texi b/doc/tutorial/ginac.texi index 40fa5624..d52e422b 100644 --- a/doc/tutorial/ginac.texi +++ b/doc/tutorial/ginac.texi @@ -1866,13 +1866,31 @@ substitutions. They are also used as arguments to the @code{ex::series} method, where the left hand side of the relation specifies the variable to expand in and the right hand side the expansion point. They can also be used for creating systems of equations that are to be solved for -unknown variables. But the most common usage of objects of this class +unknown variables. + +But the most common usage of objects of this class is rather inconspicuous in statements of the form @code{if (expand(pow(a+b,2))==a*a+2*a*b+b*b) @{...@}}. Here, an implicit conversion from @code{relational} to @code{bool} takes place. Note, however, that @code{==} here does not perform any simplifications, hence @code{expand()} must be called explicitly. +Simplifications of +relationals may be more efficient if preceded by a call to +@example +ex relational::canonical() const +@end example +which returns an equivalent relation with the zero +right-hand side. For example: +@example +possymbol p("p"); +relational rel = (p >= (p*p-1)/p); +if (ex_to(rel.canonical().normal())) + cout << "correct inequality" << endl; +@end example +However, a user shall not expect that any inequality can be fully +resolved by GiNaC. + @node Integrals, Matrices, Relations, Basic concepts @c node-name, next, previous, up @section Integrals diff --git a/ginac/relational.cpp b/ginac/relational.cpp index 892d2e91..d050b2e6 100644 --- a/ginac/relational.cpp +++ b/ginac/relational.cpp @@ -348,4 +348,11 @@ relational::operator relational::safe_bool() const } } +/** Returns an equivalent relational with zero right-hand side. + */ +ex relational::canonical() const +{ + return relational(lh-rh, _ex0, o); +} + } // namespace GiNaC diff --git a/ginac/relational.h b/ginac/relational.h index b935a7ed..a9b072a7 100644 --- a/ginac/relational.h +++ b/ginac/relational.h @@ -63,6 +63,8 @@ public: void archive(archive_node& n) const override; /** Read (a.k.a. deserialize) object from archive. */ void read_archive(const archive_node& n, lst& syms) override; + ex canonical() const; + protected: ex eval_ncmul(const exvector & v) const override; bool match_same_type(const basic & other) const override;