]> www.ginac.de Git - ginac.git/blobdiff - ginac/symbol.cpp
- fixed normal((b*a-c*a)/(4-a)) bug: heur_gcd() only works when both input
[ginac.git] / ginac / symbol.cpp
index 43927dc3a3192df4e2780440c9e701b7c3ec0066..b7408fa69653b4a2e08bb9c2e6e74ec8e9064531 100644 (file)
@@ -43,9 +43,9 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(symbol, basic)
 symbol::symbol() : inherited(TINFO_symbol)
 {
     debugmsg("symbol default constructor", LOGLEVEL_CONSTRUCT);
-    serial=next_serial++;
-    name=autoname_prefix()+ToString(serial);
-    asexinfop=new assigned_ex_info;
+    serial = next_serial++;
+    name = autoname_prefix()+ToString(serial);
+    asexinfop = new assigned_ex_info;
     setflag(status_flags::evaluated);
 }
 
@@ -64,9 +64,9 @@ symbol::symbol(const symbol & other)
 void symbol::copy(const symbol & other)
 {
     inherited::copy(other);
-    name=other.name;
-    serial=other.serial;
-    asexinfop=other.asexinfop;
+    name = other.name;
+    serial = other.serial;
+    asexinfop = other.asexinfop;
     ++asexinfop->refcount;
 }
 
@@ -92,12 +92,12 @@ void symbol::destroy(bool call_parent)
 
 // public
 
-symbol::symbol(const string & initname) : inherited(TINFO_symbol)
+symbol::symbol(const std::string & initname) : inherited(TINFO_symbol)
 {
     debugmsg("symbol constructor from string", LOGLEVEL_CONSTRUCT);
-    name=initname;
-    serial=next_serial++;
-    asexinfop=new assigned_ex_info;
+    name = initname;
+    serial = next_serial++;
+    asexinfop = new assigned_ex_info;
     setflag(status_flags::evaluated);
 }
 
@@ -148,29 +148,30 @@ basic *symbol::duplicate() const
     return new symbol(*this);
 }
 
-void symbol::print(ostream & os, unsigned upper_precedence) const
+void symbol::print(std::ostream & os, unsigned upper_precedence) const
 {
     debugmsg("symbol print",LOGLEVEL_PRINT);
     os << name;
 }
 
-void symbol::printraw(ostream & os) const
+void symbol::printraw(std::ostream & os) const
 {
     debugmsg("symbol printraw",LOGLEVEL_PRINT);
     os << "symbol(" << "name=" << name << ",serial=" << serial
        << ",hash=" << hashvalue << ",flags=" << flags << ")";
 }
 
-void symbol::printtree(ostream & os, unsigned indent) const
+void symbol::printtree(std::ostream & os, unsigned indent) const
 {
     debugmsg("symbol printtree",LOGLEVEL_PRINT);
-    os << string(indent,' ') << name << " (symbol): "
+    os << std::string(indent,' ') << name << " (symbol): "
        << "serial=" << serial
-       << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
-       << ", flags=" << flags << endl;
+       << ", hash=" << hashvalue
+       << " (0x" << std::hex << hashvalue << std::dec << ")"
+       << ", flags=" << flags << std::endl;
 }
 
-void symbol::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
+void symbol::printcsrc(std::ostream & os, unsigned type, unsigned upper_precedence) const
 {
     debugmsg("symbol print csrc", LOGLEVEL_PRINT);
     os << name;
@@ -259,6 +260,19 @@ ex symbol::subs(const lst & ls, const lst & lr) const
 
 // protected
 
+/** Implementation of ex::diff() for single differentiation of a symbol.
+ *  It returns 1 or 0.
+ *
+ *  @see ex::diff */
+ex symbol::derivative(const symbol & s) const
+{
+    if (compare_same_type(s)) {
+        return _ex0();
+    } else {
+        return _ex1();
+    }
+}
+
 int symbol::compare_same_type(const basic & other) const
 {
     GINAC_ASSERT(is_of_type(other,symbol));
@@ -322,9 +336,9 @@ void symbol::unassign(void)
 
 // private
 
-string & symbol::autoname_prefix(void)
+std::string & symbol::autoname_prefix(void)
 {
-    static string * s=new string("symbol");
+    static std::string * s=new std::string("symbol");
     return *s;
 }
 
@@ -336,7 +350,7 @@ string & symbol::autoname_prefix(void)
 
 unsigned symbol::next_serial=0;
 
-// string const symbol::autoname_prefix="symbol";
+// std::string const symbol::autoname_prefix="symbol";
 
 //////////
 // global constants