X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fsymbol.cpp;h=a84ae4a42623bf915af1ad037abd99b1335c3803;hp=3b3c88202463c5a71d8797741395be5f63641ff8;hb=6a5d85aac330ef87ebdd46ae1c3f4c1e1b7bed3f;hpb=13896261ee985f23e5b5648532e70f0cce704ede diff --git a/ginac/symbol.cpp b/ginac/symbol.cpp index 3b3c8820..a84ae4a4 100644 --- a/ginac/symbol.cpp +++ b/ginac/symbol.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's symbolic objects. */ /* - * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2007 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 @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -28,6 +28,7 @@ #include "archive.h" #include "tostring.h" #include "utils.h" +#include "inifcns.h" namespace GiNaC { @@ -41,30 +42,88 @@ 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) + : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static), domain(domain::complex) { setflag(status_flags::evaluated | status_flags::expanded); } +// realsymbol + +realsymbol::realsymbol() +{ + domain = domain::real; +} + +// possymbol + +possymbol::possymbol() +{ + domain = domain::positive; +} + ////////// // other constructors ////////// // public -symbol::symbol(const std::string & initname) - : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()) +// symbol + +symbol::symbol(const std::string & initname, unsigned domain) + : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static), domain(domain) +{ + setflag(status_flags::evaluated | status_flags::expanded); +} + +symbol::symbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain) + : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), ret_type(rt), ret_type_tinfo(rtt), domain(domain) { setflag(status_flags::evaluated | status_flags::expanded); } -symbol::symbol(const std::string & initname, const std::string & texname) - : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname) +symbol::symbol(const std::string & initname, const std::string & texname, unsigned domain) + : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), ret_type(return_types::commutative), ret_type_tinfo(&symbol::tinfo_static), domain(domain) { setflag(status_flags::evaluated | status_flags::expanded); } +symbol::symbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain) + : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), ret_type(rt), ret_type_tinfo(rtt), domain(domain) +{ + 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, tinfo_t rtt, unsigned domain) + : symbol(initname, rt, rtt, domain) { } + +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 ////////// @@ -73,11 +132,15 @@ symbol::symbol(const std::string & initname, const std::string & texname) symbol::symbol(const archive_node &n, lst &sym_lst) : inherited(n, sym_lst), asexinfop(new assigned_ex_info), serial(next_serial++) { - if (!(n.find_string("name", name))) + if (!n.find_string("name", name)) name = autoname_prefix() + ToString(serial); - if (!(n.find_string("TeXname", TeX_name))) + if (!n.find_string("TeXname", TeX_name)) TeX_name = default_TeX_name(); - setflag(status_flags::evaluated); + if (!n.find_unsigned("domain", domain)) + domain = domain::complex; + if (!n.find_unsigned("return_type", ret_type)) + ret_type = return_types::commutative; + setflag(status_flags::evaluated | status_flags::expanded); } /** Unarchive the object. */ @@ -103,6 +166,10 @@ 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 != domain::complex) + n.add_unsigned("domain", domain); + if (ret_type != return_types::commutative) + n.add_unsigned("return_type", ret_type); } ////////// @@ -126,6 +193,7 @@ void symbol::do_print_tree(const print_tree & c, unsigned level) const c.s << std::string(level, ' ') << name << " (" << class_name() << ")" << " @" << this << ", serial=" << serial << std::hex << ", hash=0x" << hashvalue << ", flags=0x" << flags << std::dec + << ", domain=" << domain << std::endl; } @@ -139,14 +207,19 @@ void symbol::do_print_python_repr(const print_python_repr & c, unsigned level) c bool symbol::info(unsigned inf) const { - if (inf==info_flags::symbol) return true; - if (inf==info_flags::polynomial || - inf==info_flags::integer_polynomial || - inf==info_flags::cinteger_polynomial || - inf==info_flags::rational_polynomial || - inf==info_flags::crational_polynomial || - inf==info_flags::rational_function) + if (inf == info_flags::symbol) + return true; + if (inf == info_flags::polynomial || + inf == info_flags::integer_polynomial || + inf == info_flags::cinteger_polynomial || + inf == info_flags::rational_polynomial || + inf == info_flags::crational_polynomial || + inf == info_flags::rational_function) return true; + if (inf == info_flags::real) + return domain==domain::real || domain==domain::positive; + if (inf == info_flags::positive || inf == info_flags::nonnegative) + return domain == domain::positive; else return inherited::info(inf); } @@ -167,6 +240,34 @@ ex symbol::eval(int level) const } } +ex symbol::conjugate() const +{ + if (this->domain == domain::complex) { + return conjugate_function(*this).hold(); + } else { + return *this; + } +} + +ex symbol::real_part() const +{ + if (domain==domain::real || domain==domain::positive) + return *this; + return real_part_function(*this).hold(); +} + +ex symbol::imag_part() const +{ + if (domain==domain::real || domain==domain::positive) + return 0; + return imag_part_function(*this).hold(); +} + +bool symbol::is_polynomial(const ex & var) const +{ + return true; +} + // protected /** Implementation of ex::diff() for single differentiation of a symbol. @@ -198,7 +299,7 @@ bool symbol::is_equal_same_type(const basic & other) const unsigned symbol::calchash() const { - hashvalue = golden_ratio_hash(tinfo() ^ serial); + hashvalue = golden_ratio_hash((p_int)tinfo() ^ serial); setflag(status_flags::hash_calculated); return hashvalue; } @@ -276,7 +377,7 @@ unsigned symbol::next_serial = 0; ////////// /** Default ctor. Defaults to unassigned. */ -symbol::assigned_ex_info::assigned_ex_info() : is_assigned(false) +symbol::assigned_ex_info::assigned_ex_info() throw() : is_assigned(false) { }