]> www.ginac.de Git - ginac.git/commitdiff
Made class possymbol for positive symbols and documented it.
authorChris Dams <Chris.Dams@mi.infn.it>
Mon, 19 Jun 2006 15:29:43 +0000 (15:29 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Mon, 19 Jun 2006 15:29:43 +0000 (15:29 +0000)
doc/tutorial/ginac.texi
ginac/symbol.cpp
ginac/symbol.h

index 26f004ed73b2cf39efe9124f941741a1e14b4750..bdea81b80a842aa0c6c71a5b193dbcf8e8754f60 100644 (file)
@@ -1155,11 +1155,17 @@ in the complex domain.  As a consequence, operations like complex conjugation,
 for example (@pxref{Complex expressions}), do @emph{not} evaluate if applied
 to such symbols. Likewise @code{log(exp(x))} does not evaluate to @code{x},
 because of the unknown imaginary part of @code{x}.
-On the other hand, if you are sure that your symbols will hold only real values, you
-would like to have such functions evaluated. Therefore GiNaC allows you to specify
+On the other hand, if you are sure that your symbols will hold only real
+values, you would like to have such functions evaluated. Therefore GiNaC
+allows you to specify
 the domain of the symbol. Instead of @code{symbol x("x");} you can write
 @code{realsymbol x("x");} to tell GiNaC that @code{x} stands in for real values.
 
+@cindex @code{possymbol()}
+Furthermore, it is also possible to declare a symbol as positive. This will,
+for instance, enable the automatic simplification of @code{abs(x)} into 
+@code{x}. This is done by declaying the symbol as @code{possymbol x("x");}.
+
 
 @node Numbers, Constants, Symbols, Basic concepts
 @c    node-name, next, previous, up
index 7e3b49d8bc7c0e59bcecf4c4034cfaaed1050a47..bf58fd4bacf6bc2833d763af347ec8c9ca2cf839 100644 (file)
@@ -57,6 +57,13 @@ realsymbol::realsymbol()
        domain = domain::real;
 }
 
+// possymbol
+
+possymbol::possymbol()
+{
+       domain = domain::positive;
+}
+
 //////////
 // other constructors
 //////////
@@ -103,6 +110,20 @@ realsymbol::realsymbol(const std::string & initname, unsigned rt, tinfo_t rtt, u
 realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
  : symbol(initname, texname, rt, rtt, domain) { }
 
+// possymbol
+       
+possymbol::possymbol(const std::string & initname, unsigned domain)
+ : symbol(initname, domain) { }
+
+possymbol::possymbol(const std::string & initname, const std::string & texname, unsigned domain)
+ : symbol(initname, texname, domain) { }
+
+possymbol::possymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain)
+ : symbol(initname, rt, rtt, domain) { }
+
+possymbol::possymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
+ : symbol(initname, texname, rt, rtt, domain) { }
+
 //////////
 // archiving
 //////////
index 90013144ccd5d7f88e28a280055b54c814c193df..2a5ae5cc57c0f72a1af29362c3ce4d4b62960b92 100644 (file)
@@ -41,6 +41,7 @@ class symbol : public basic
        GINAC_DECLARE_REGISTERED_CLASS(symbol, basic)
 
        friend class realsymbol;
+       friend class possymbol;
 
 // types
        
@@ -127,6 +128,19 @@ public:
 };
 
 
+/** Specialization of symbol to real domain */
+class possymbol : public symbol
+{
+       // constructors
+public:
+       possymbol();
+       explicit possymbol(const std::string & initname, unsigned domain = domain::positive);
+       possymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::positive);
+       possymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::positive);
+       possymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::positive);
+};
+
+
 // utility functions
 
 /** Specialization of is_exactly_a<realsymbol>(obj) for realsymbol objects. */
@@ -138,6 +152,15 @@ template<> inline bool is_exactly_a<realsymbol>(const basic & obj)
        return domain==domain::real || domain==domain::positive;
 }
 
+/** Specialization of is_exactly_a<possymbol>(obj) for possymbol objects. */
+template<> inline bool is_exactly_a<possymbol>(const basic & obj)
+{
+       if (obj.tinfo() != &symbol::tinfo_static)
+               return false;
+       unsigned domain = static_cast<const symbol &>(obj).get_domain();
+       return domain == domain::positive;
+}
+
 // wrapper functions around member functions
 inline void unassign(symbol & symarg)
 { symarg.unassign(); }