symbols can be made noncommutative (see symbol constructors); some feedback
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 26 Aug 2003 21:01:27 +0000 (21:01 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Tue, 26 Aug 2003 21:01:27 +0000 (21:01 +0000)
on the usefulness of this would be appreciated

ginac/symbol.cpp
ginac/symbol.h

index 3b3c88202463c5a71d8797741395be5f63641ff8..dd6e664394a4beae6f39e178372c865be1016f54 100644 (file)
@@ -42,7 +42,7 @@ GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(symbol, basic,
 //////////
 
 symbol::symbol()
- : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(autoname_prefix() + ToString(serial)), TeX_name(name)
+ : 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)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -54,13 +54,25 @@ symbol::symbol()
 // 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())
+ : 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)
 {
        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)
+ : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), ret_type(return_types::commutative), ret_type_tinfo(TINFO_symbol)
+{
+       setflag(status_flags::evaluated | status_flags::expanded);
+}
+
+symbol::symbol(const std::string & initname, unsigned rt, unsigned rtt)
+ : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), ret_type(rt), ret_type_tinfo(rtt)
+{
+       setflag(status_flags::evaluated | status_flags::expanded);
+}
+
+symbol::symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt)
+ : inherited(TINFO_symbol), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), ret_type(rt), ret_type_tinfo(rtt)
 {
        setflag(status_flags::evaluated | status_flags::expanded);
 }
@@ -71,13 +83,17 @@ symbol::symbol(const std::string & initname, const std::string & texname)
 
 /** Construct object from archive_node. */
 symbol::symbol(const archive_node &n, lst &sym_lst)
- : inherited(n, sym_lst), asexinfop(new assigned_ex_info), serial(next_serial++)
+ : inherited(n, sym_lst), asexinfop(new assigned_ex_info), serial(next_serial++), ret_type(return_types::commutative), ret_type_tinfo(TINFO_symbol)
 {
        if (!(n.find_string("name", name)))
                name = autoname_prefix() + ToString(serial);
        if (!(n.find_string("TeXname", TeX_name)))
                TeX_name = default_TeX_name();
-       setflag(status_flags::evaluated);
+       if (!n.find_unsigned("return_type", ret_type))
+               ret_type = return_types::commutative;
+       if (!n.find_unsigned("return_type_tinfo", ret_type_tinfo))
+               ret_type_tinfo = TINFO_symbol;
+       setflag(status_flags::evaluated | status_flags::expanded);
 }
 
 /** Unarchive the object. */
@@ -103,6 +119,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 (ret_type != return_types::commutative)
+               n.add_unsigned("return_type", ret_type);
+       if (ret_type_tinfo != TINFO_symbol)
+               n.add_unsigned("return_type_tinfo", ret_type_tinfo);
 }
 
 //////////
index 450a2df43deac6dec1f710e96662eec91ae4bc3b..707aedb1d7981bc02741adb77c888e6add4d6c30 100644 (file)
@@ -58,7 +58,9 @@ class symbol : public basic
        // other constructors
 public:
        explicit symbol(const std::string & initname);
-       explicit symbol(const std::string & initname, const std::string & texname);
+       symbol(const std::string & initname, const std::string & texname);
+       symbol(const std::string & initname, unsigned rt, unsigned rtt);
+       symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned rtt);
        
        // functions overriding virtual functions from base classes
 public:
@@ -70,6 +72,8 @@ public:
        ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const;
        ex to_rational(lst &repl_lst) const;
        ex to_polynomial(lst &repl_lst) const;
+       unsigned return_type() const { return ret_type; }
+       unsigned return_type_tinfo() const { return ret_type_tinfo; }
 protected:
        ex derivative(const symbol & s) const;
        bool is_equal_same_type(const basic & other) const;
@@ -97,6 +101,8 @@ protected:
        unsigned serial;                 ///< unique serial number for comparison
        std::string name;                ///< printname of this symbol
        std::string TeX_name;            ///< LaTeX name of this symbol
+       unsigned ret_type;               ///< value returned by return_type()
+       unsigned ret_type_tinfo;         ///< value returned by return_type_tinfo()
 private:
        static unsigned next_serial;
 };