]> www.ginac.de Git - ginac.git/blobdiff - ginac/relational.cpp
- revamped indexed objects
[ginac.git] / ginac / relational.cpp
index a71a90af1859d1eec591d7f022815f7b0e02ceb7..20ff40b8386a7e3460e90b2366501b7fe5cafd65 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of relations between expressions */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 #include "utils.h"
 #include "debugmsg.h"
 
-#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_NAMESPACE_GINAC
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(relational, basic)
 
 //////////
-// default constructor, destructor, copy constructor assignment operator and helpers
+// default ctor, dtor, copy ctor assignment operator and helpers
 //////////
 
 // public
 
 relational::relational() : basic(TINFO_relational)
 {
-       debugmsg("relational default constructor",LOGLEVEL_CONSTRUCT);
-}
-
-relational::~relational()
-{
-       debugmsg("relational destructor",LOGLEVEL_DESTRUCT);
-       destroy(0);
-}
-
-relational::relational(const relational & other)
-{
-       debugmsg("relational copy constructor",LOGLEVEL_CONSTRUCT);
-       copy(other);
-}
-
-const relational & relational::operator=(const relational & other)
-{
-       debugmsg("relational operator=",LOGLEVEL_ASSIGNMENT);
-       if (this != &other) {
-               destroy(1);
-               copy(other);
-       }
-       return *this;
+       debugmsg("relational default ctor",LOGLEVEL_CONSTRUCT);
 }
 
 // protected
@@ -83,14 +59,14 @@ void relational::destroy(bool call_parent)
 }
 
 //////////
-// other constructors
+// other ctors
 //////////
 
 // public
 
 relational::relational(const ex & lhs, const ex & rhs, operators oper) : basic(TINFO_relational)
 {
-       debugmsg("relational constructor ex,ex,operator",LOGLEVEL_CONSTRUCT);
+       debugmsg("relational ctor ex,ex,operator",LOGLEVEL_CONSTRUCT);
        lh=lhs;
        rh=rhs;
        o=oper;
@@ -103,7 +79,7 @@ relational::relational(const ex & lhs, const ex & rhs, operators oper) : basic(T
 /** Construct object from archive_node. */
 relational::relational(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
-       debugmsg("relational constructor from archive_node", LOGLEVEL_CONSTRUCT);
+       debugmsg("relational ctor from archive_node", LOGLEVEL_CONSTRUCT);
        unsigned int opi;
        if (!(n.find_unsigned("op", opi)))
                throw (std::runtime_error("unknown relational operator in archive"));
@@ -133,12 +109,6 @@ void relational::archive(archive_node &n) const
 
 // public
 
-basic * relational::duplicate() const
-{
-       debugmsg("relational duplicate",LOGLEVEL_DUPLICATE);
-       return new relational(*this);
-}
-
 void relational::print(std::ostream & os, unsigned upper_precedence) const
 {
        debugmsg("relational print",LOGLEVEL_PRINT);
@@ -173,7 +143,7 @@ void relational::print(std::ostream & os, unsigned upper_precedence) const
 void relational::printraw(std::ostream & os) const
 {
        debugmsg("relational printraw",LOGLEVEL_PRINT);
-       os << "RELATIONAL(";
+       os << class_name() << "(";
        lh.printraw(os);
        os << ",";
        rh.printraw(os);
@@ -280,27 +250,24 @@ ex & relational::let_op(int i)
        
 ex relational::eval(int level) const
 {
-       if (level==1) {
+       if (level==1)
                return this->hold();
-       }
-       if (level == -max_recursion_level) {
+       
+       if (level == -max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
-       }
-       return (new relational(lh.eval(level-1),rh.eval(level-1),o))->
-                       setflag(status_flags::dynallocated  |
-                                       status_flags::evaluated );
+       
+       return (new relational(lh.eval(level-1),rh.eval(level-1),o))->setflag(status_flags::dynallocated | status_flags::evaluated);
 }
 
 ex relational::evalf(int level) const
 {
-       if (level==1) {
+       if (level==1)
                return *this;
-       }
-       if (level == -max_recursion_level) {
+       
+       if (level==-max_recursion_level)
                throw(std::runtime_error("max recursion level reached"));
-       }
-       return (new relational(lh.eval(level-1),rh.eval(level-1),o))->
-                       setflag(status_flags::dynallocated);
+       
+       return (new relational(lh.eval(level-1),rh.eval(level-1),o))->setflag(status_flags::dynallocated);
 }
 
 ex relational::simplify_ncmul(const exvector & v) const
@@ -318,18 +285,16 @@ int relational::compare_same_type(const basic & other) const
        int cmpval;
        
        if (o == oth.o) {
-               cmpval=lh.compare(oth.lh);
-               if (cmpval==0) {
+               cmpval = lh.compare(oth.lh);
+               if (cmpval==0)
                        return rh.compare(oth.rh);
-               } else {
+               else
                        return cmpval;
-               }
        }
-       if (o<oth.o) {
+       if (o<oth.o)
                return -1;
-       } else {
+       else
                return 1;
-       }
 }
 
 unsigned relational::return_type(void) const
@@ -369,34 +334,28 @@ relational::operator bool() const
        // please note that (a<b) == false does not imply (a>=b) == true
        // a false result means the comparison is either false or undecidable
        // (except for !=, where true means unequal or undecidable)
-       ex df=lh-rh;
-       if (!is_ex_exactly_of_type(df,numeric)) {
-               return o==not_equal ? true : false; // cannot decide on non-numerical results
-       }
-       int cmpval=ex_to_numeric(df).compare(_num0());
+       ex df = lh-rh;
+       if (!is_ex_exactly_of_type(df,numeric))
+               // cannot decide on non-numerical results
+               return o==not_equal ? true : false;
+       
+       int cmpval = ex_to_numeric(df).compare(_num0());
        switch (o) {
        case equal:
                return cmpval==0;
-               break;
        case not_equal:
                return cmpval!=0;
-               break;
        case less:
                return cmpval<0;
-               break;
        case less_or_equal:
                return cmpval<=0;
-               break;
        case greater:
                return cmpval>0;
-               break;
        case greater_or_equal:
                return cmpval>=0;
-               break;
        default:
                throw(std::logic_error("invalid relational operator"));
        }
-       return 0;
 }
 
 //////////
@@ -405,15 +364,6 @@ relational::operator bool() const
 
 // protected
 
-unsigned relational::precedence=20;
-
-//////////
-// global constants
-//////////
-
-const relational some_relational;
-const type_info & typeid_relational=typeid(some_relational);
+unsigned relational::precedence = 20;
 
-#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC