From: Jens Vollinga Date: Thu, 8 Jan 2004 18:48:10 +0000 (+0000) Subject: * Added realsymbol class. X-Git-Tag: release_1-2-0~22 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=3c75f4ed241bb89f09fd27b9ec6cd7bd240c2cda;hp=6d225ee55693c0617d254e6fa283c00c71bd2919 * Added realsymbol class. * Renamed symbol_options to domain. --- diff --git a/ginac/flags.h b/ginac/flags.h index 616cc56f..1bd1bf42 100644 --- a/ginac/flags.h +++ b/ginac/flags.h @@ -47,13 +47,11 @@ public: }; }; -/** Flags to decide how conjugate should treat a symbol */ -class symbol_options { +/** Domain of an object */ +class domain { public: enum { - /** Symbol is treated like a complex valued expression */ complex, - /** Symbol is treated like a real valued expression */ real }; }; diff --git a/ginac/inifcns_trans.cpp b/ginac/inifcns_trans.cpp index b98d36b8..08758f56 100644 --- a/ginac/inifcns_trans.cpp +++ b/ginac/inifcns_trans.cpp @@ -124,7 +124,7 @@ static ex log_eval(const ex & x) // log(exp(t)) -> t (if -Pi < t.imag() <= Pi): if (is_ex_the_function(x, exp)) { const ex &t = x.op(0); - if (is_a(t) && (ex_to(t).get_domain() == symbol_options::real)) { + if (is_a(t) && t.info(info_flags::real)) { return t; } if (t.info(info_flags::numeric)) { diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 06016984..76d063eb 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -42,18 +42,29 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic, // default constructor ////////// +// symbol + symbol::symbol() - : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), ret_type(return_types::commutative), ret_type_tinfo(TINFO_symbol), domain(symbol_options::complex) + : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), ret_type(return_types::commutative), ret_type_tinfo(TINFO_symbol), domain(domain::complex) { setflag(status_flags::evaluated | status_flags::expanded); } +// realsymbol + +realsymbol::realsymbol() +{ + domain = domain::real; +} + ////////// // other constructors ////////// // public +// symbol + symbol::symbol(const std::string & initname, unsigned domain) : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), ret_type(return_types::commutative), ret_type_tinfo(TINFO_symbol), domain(domain) { @@ -78,6 +89,20 @@ symbol::symbol(const std::string & initname, const std::string & texname, unsign setflag(status_flags::evaluated | status_flags::expanded); } +// realsymbol + +realsymbol::realsymbol(const std::string & initname, unsigned domain) + : symbol(initname, domain) { } + +realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned domain) + : symbol(initname, texname, domain) { } + +realsymbol::realsymbol(const std::string & initname, unsigned rt, unsigned rtt, unsigned domain) + : symbol(initname, rt, rtt, domain) { } + +realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt, unsigned domain) + : symbol(initname, texname, rt, rtt, domain) { } + ////////// // archiving ////////// @@ -91,7 +116,7 @@ symbol::symbol(const archive_node &n, lst &sym_lst) if (!n.find_string("TeXname", TeX_name)) TeX_name = default_TeX_name(); if (!n.find_unsigned("domain", domain)) - domain = symbol_options::complex; + domain = domain::complex; if (!n.find_unsigned("return_type", ret_type)) ret_type = return_types::commutative; if (!n.find_unsigned("return_type_tinfo", ret_type_tinfo)) @@ -122,7 +147,7 @@ void symbol::archive(archive_node &n) const n.add_string("name", name); if (TeX_name != default_TeX_name()) n.add_string("TeX_name", TeX_name); - if (domain != symbol_options::complex) + if (domain != domain::complex) n.add_unsigned("domain", domain); if (ret_type != return_types::commutative) n.add_unsigned("return_type", ret_type); @@ -175,7 +200,7 @@ bool symbol::info(unsigned inf) const inf == info_flags::rational_function) return true; if (inf == info_flags::real) - return domain == symbol_options::real; + return domain == domain::real; else return inherited::info(inf); } @@ -198,7 +223,7 @@ ex symbol::eval(int level) const ex symbol::conjugate() const { - if (this->domain == symbol_options::complex) { + if (this->domain == domain::complex) { return GiNaC::conjugate(*this).hold(); } else { return *this; diff --git a/ginac/symbol.h b/ginac/symbol.h index a8e667f4..69233002 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -40,6 +40,8 @@ class symbol : public basic { GINAC_DECLARE_REGISTERED_CLASS(symbol, basic) + friend class realsymbol; + // types /** Symbols as keys to expressions - only for ginsh. */ @@ -54,10 +56,10 @@ class symbol : public basic // other constructors public: - explicit symbol(const std::string & initname, unsigned domain = symbol_options::complex); - symbol(const std::string & initname, const std::string & texname, unsigned domain = symbol_options::complex); - symbol(const std::string & initname, unsigned rt, unsigned rtt, unsigned domain = symbol_options::complex); - symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt, unsigned domain = symbol_options::complex); + explicit symbol(const std::string & initname, unsigned domain = domain::complex); + symbol(const std::string & initname, const std::string & texname, unsigned domain = domain::complex); + symbol(const std::string & initname, unsigned rt, unsigned rtt, unsigned domain = domain::complex); + symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt, unsigned domain = domain::complex); // functions overriding virtual functions from base classes public: @@ -83,7 +85,6 @@ public: void unassign(); void set_name(const std::string & n) { name = n; } std::string get_name() const { return name; } - unsigned get_domain() const { return domain; } protected: void do_print(const print_context & c, unsigned level) const; void do_print_latex(const print_latex & c, unsigned level) const; @@ -108,12 +109,31 @@ private: }; +/** Specialization of symbol to real domain */ +class realsymbol : public symbol +{ + // constructors +public: + realsymbol(); + explicit realsymbol(const std::string & initname, unsigned domain = domain::real); + realsymbol(const std::string & initname, const std::string & texname, unsigned domain = domain::real); + realsymbol(const std::string & initname, unsigned rt, unsigned rtt, unsigned domain = domain::real); + realsymbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt, unsigned domain = domain::real); +}; + + // utility functions /** Specialization of is_exactly_a(obj) for symbol objects. */ template<> inline bool is_exactly_a(const basic & obj) { - return obj.tinfo()==TINFO_symbol; + return (obj.tinfo() == TINFO_symbol) && obj.info(info_flags::real); +} + +/** Specialization of is_exactly_a(obj) for realsymbol objects. */ +template<> inline bool is_exactly_a(const basic & obj) +{ + return (obj.tinfo() == TINFO_symbol) && obj.info(info_flags::real); } // wrapper functions around member functions