return seq.begin()->rest.return_type();
}
-const basic* add::return_type_tinfo() const
+tinfo_t add::return_type_tinfo() const
{
if (seq.empty())
return this;
protected:
ex derivative(const symbol & s) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
ex thisexpairseq(const epvector & v, const ex & oc) const;
ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const;
expair split_ex_to_pair(const ex & e) const;
return return_types::commutative;
}
-const basic* basic::return_type_tinfo() const
+tinfo_t basic::return_type_tinfo() const
{
- return this;
+ return tinfo_key;
}
/** Compute the hash value of an object and if it makes sense to store it in
// noncommutativity
virtual unsigned return_type() const;
- virtual const basic* return_type_tinfo() const;
+ virtual tinfo_t return_type_tinfo() const;
// complex conjugation
virtual ex conjugate() const;
print_func<print_dflt>(&clifford::do_print_dflt).
print_func<print_latex>(&clifford::do_print_latex))
+const tinfo_static_t clifford::return_type_tinfo_static[256] = {{}};
+
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(diracone, tensor,
print_func<print_dflt>(&diracone::do_print).
print_func<print_latex>(&diracone::do_print_latex))
/** Check whether a given tinfo key (as returned by return_type_tinfo()
* is that of a clifford object (with an arbitrary representation label). */
-static bool is_clifford_tinfo(const basic* ti)
+bool is_clifford_tinfo(tinfo_t ti)
{
- return ti->tinfo() == &clifford::tinfo_static;
+ p_int start_loc=(p_int)&clifford::return_type_tinfo_static;
+ return (p_int)ti>=start_loc && (p_int)ti<start_loc+256;
}
/** Extract representation label from tinfo key (as returned by
* return_type_tinfo()). */
-static unsigned char get_representation_label(const basic* ti)
+static unsigned char get_representation_label(tinfo_t ti)
{
- return ((clifford*)ti)->get_representation_label();
+ return (unsigned char)((p_int)ti-(p_int)&clifford::return_type_tinfo_static);
}
/** Take trace of a string of an even number of Dirac gammas given a vector
class clifford : public indexed
{
GINAC_DECLARE_REGISTERED_CLASS(clifford, indexed)
+public:
+ static const tinfo_static_t return_type_tinfo_static[256];
// other constructors
public:
ex thiscontainer(const exvector & v) const;
ex thiscontainer(std::auto_ptr<exvector> vp) const;
unsigned return_type() const { return return_types::noncommutative; }
- const basic* return_type_tinfo() const { return this; }
+ tinfo_t return_type_tinfo() const { return clifford::return_type_tinfo_static+representation_label; }
// non-virtual functions in this class
public:
// global functions
+/** Check whether a given tinfo key (as returned by return_type_tinfo()
+ * is that of a clifford object (with an arbitrary representation label).
+ *
+ * @param ti tinfo key */
+bool is_clifford_tinfo(tinfo_t ti);
+
/** Create a Clifford unity object.
*
* @param rl Representation label
GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed)
+const tinfo_static_t color::return_type_tinfo_static[256] = {{}};
+
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(su3one, tensor,
print_func<print_dflt>(&su3one::do_print).
print_func<print_latex>(&su3one::do_print_latex))
/** Check whether a given tinfo key (as returned by return_type_tinfo()
* is that of a color object (with an arbitrary representation label). */
-static bool is_color_tinfo(const basic* ti)
+static bool is_color_tinfo(tinfo_t ti)
{
- return ti->tinfo() == &color::tinfo_static;
+ p_int start_loc=(p_int)&color::return_type_tinfo_static;
+ return (p_int)ti>=start_loc && (p_int)ti<start_loc+256;
}
/** Extract representation label from tinfo key (as returned by
* return_type_tinfo()). */
-static unsigned char get_representation_label(const basic* ti)
+static unsigned char get_representation_label(tinfo_t ti)
{
- return ((color*)ti)->get_representation_label();
+ return (unsigned char)((p_int)ti-(p_int)&color::return_type_tinfo_static);
}
ex color_trace(const ex & e, const std::set<unsigned char> & rls)
class color : public indexed
{
GINAC_DECLARE_REGISTERED_CLASS(color, indexed)
+public:
+ static const tinfo_static_t return_type_tinfo_static[256];
// other constructors
public:
ex thiscontainer(const exvector & v) const;
ex thiscontainer(std::auto_ptr<exvector> vp) const;
unsigned return_type() const { return return_types::noncommutative; }
- const basic* return_type_tinfo() const { return this; }
+ tinfo_t return_type_tinfo() const { return color::return_type_tinfo_static+representation_label; }
// non-virtual functions in this class
public:
// noncommutativity
unsigned return_type() const { return bp->return_type(); }
- const basic* return_type_tinfo() const { return bp->return_type_tinfo(); }
+ tinfo_t return_type_tinfo() const { return bp->return_type_tinfo(); }
unsigned gethash() const { return bp->gethash(); }
return *this;
}
- function_options & set_return_type(unsigned rt);
+ function_options & set_return_type(unsigned rt, tinfo_t rtt=NULL);
function_options & do_not_evalf_params();
function_options & remember(unsigned size, unsigned assoc_size=0,
unsigned strategy=remember_strategies::delete_never);
bool use_return_type;
unsigned return_type;
- const basic* return_type_tinfo;
+ tinfo_t return_type_tinfo;
bool use_remember;
unsigned remember_size;
bool is_equal_same_type(const basic & other) const;
bool match_same_type(const basic & other) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
// new virtual functions which can be overridden by derived classes
// none
return *this;
}
-function_options & function_options::set_return_type(unsigned rt)
+function_options & function_options::set_return_type(unsigned rt, tinfo_t rtt)
{
use_return_type = true;
return_type = rt;
+ return_type_tinfo = rtt;
return *this;
}
}
}
-const basic* function::return_type_tinfo() const
+tinfo_t function::return_type_tinfo() const
{
GINAC_ASSERT(serial<registered_functions().size());
const function_options &opt = registered_functions()[serial];
if (opt.use_return_type) {
// Return type was explicitly specified
- return this;
+ return opt.return_type_tinfo;
} else {
// Default behavior is to use the return type of the first
// argument. Thus, exp() of a matrix behaves like a matrix, etc.
ex thiscontainer(const exvector & v) const;
ex thiscontainer(std::auto_ptr<exvector> vp) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const { return op(0).return_type_tinfo(); }
+ tinfo_t return_type_tinfo() const { return op(0).return_type_tinfo(); }
ex expand(unsigned options = 0) const;
// new virtual functions which can be overridden by derived classes
return f.return_type();
}
-const basic* integral::return_type_tinfo() const
+tinfo_t integral::return_type_tinfo() const
{
return f.return_type_tinfo();
}
ex expand(unsigned options = 0) const;
exvector get_free_indices() const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
ex conjugate() const;
ex eval_integ() const;
protected:
#include "mul.h"
#include "add.h"
-#include "color.h"
-#include "clifford.h"
#include "power.h"
#include "operators.h"
#include "matrix.h"
}
if ((rt == return_types::noncommutative) && (!all_commutative)) {
// another nc element found, compare type_infos
- if (noncommutative_element->rest.return_type_tinfo()->tinfo() == &clifford::tinfo_static) {
- if (i->rest.return_type_tinfo()->tinfo() != &clifford::tinfo_static ||
- ((clifford*)(noncommutative_element->rest.return_type_tinfo()))->get_representation_label() !=
- ((clifford*)(i->rest.return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
- return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->rest.return_type_tinfo()->tinfo() == &color::tinfo_static) {
- if (i->rest.return_type_tinfo()->tinfo() != &color::tinfo_static ||
- ((color*)(noncommutative_element->rest.return_type_tinfo()))->get_representation_label() !=
- ((color*)(i->rest.return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
- return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->rest.return_type_tinfo()->tinfo() != i->rest.return_type_tinfo()->tinfo()) {
+ if (noncommutative_element->rest.return_type_tinfo() != i->rest.return_type_tinfo()) {
+ // different types -> mul is ncc
return return_types::noncommutative_composite;
}
}
return all_commutative ? return_types::commutative : return_types::noncommutative;
}
-const basic* mul::return_type_tinfo() const
+tinfo_t mul::return_type_tinfo() const
{
if (seq.empty())
return this; // mul without factors: should not happen
ex derivative(const symbol & s) const;
ex eval_ncmul(const exvector & v) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
ex thisexpairseq(const epvector & v, const ex & oc) const;
ex thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const;
expair split_ex_to_pair(const ex & e) const;
#include "add.h"
#include "mul.h"
#include "clifford.h"
-#include "color.h"
#include "matrix.h"
#include "archive.h"
#include "indexed.h"
size_t assoc_num = assocseq.size();
exvectorvector evv;
- std::vector<const basic*> rttinfos;
+ std::vector<tinfo_t> rttinfos;
evv.reserve(assoc_num);
rttinfos.reserve(assoc_num);
cit = assocseq.begin(), citend = assocseq.end();
while (cit != citend) {
- const basic* ti = cit->return_type_tinfo();
+ tinfo_t ti = cit->return_type_tinfo();
size_t rtt_num = rttinfos.size();
// search type in vector of known types
for (i=0; i<rtt_num; ++i) {
- tinfo_t tinf = ti->tinfo();
- if (tinf == rttinfos[i]->tinfo()) {
- if (tinf == &clifford::tinfo_static) {
- if (((clifford*)ti)->get_representation_label() == ((clifford*)rttinfos[i])->get_representation_label()) {
- evv[i].push_back(*cit);
- break;
- }
- } else if (tinf == &color::tinfo_static) {
- if (((color*)ti)->get_representation_label() == ((color*)rttinfos[i])->get_representation_label()) {
- evv[i].push_back(*cit);
- break;
- }
- } else {
- evv[i].push_back(*cit);
- break;
- }
+ if(ti == rttinfos[i]) {
+ evv[i].push_back(*cit);
+ break;
}
}
if (i >= rtt_num) {
return exprseq::conjugate();
}
- if (return_type_tinfo()->tinfo() != &clifford::tinfo_static) {
+ if (!is_clifford_tinfo(return_type_tinfo())) {
return exprseq::conjugate();
}
}
if ((rt == return_types::noncommutative) && (!all_commutative)) {
// another nc element found, compare type_infos
- if (noncommutative_element->return_type_tinfo()->tinfo() == &clifford::tinfo_static) {
- if (i->return_type_tinfo()->tinfo() != &clifford::tinfo_static ||
- ((clifford*)(noncommutative_element->return_type_tinfo()))->get_representation_label() !=
- ((clifford*)(i->return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
+ if(noncommutative_element->return_type_tinfo() != i->return_type_tinfo())
return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->return_type_tinfo()->tinfo() == &color::tinfo_static) {
- if (i->return_type_tinfo()->tinfo() != &color::tinfo_static ||
- ((color*)(noncommutative_element->return_type_tinfo()))->get_representation_label() !=
- ((color*)(i->return_type_tinfo()))->get_representation_label()) {
- // diffent types -> mul is ncc
- return return_types::noncommutative_composite;
- }
- } else if (noncommutative_element->return_type_tinfo()->tinfo() != i->return_type_tinfo()->tinfo()) {
- return return_types::noncommutative_composite;
- }
}
++i;
}
return all_commutative ? return_types::commutative : return_types::noncommutative;
}
-const basic* ncmul::return_type_tinfo() const
+tinfo_t ncmul::return_type_tinfo() const
{
if (seq.empty())
return this;
protected:
ex derivative(const symbol & s) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
// new virtual functions which can be overridden by derived classes
// none
return basis.return_type();
}
-const basic* power::return_type_tinfo() const
+tinfo_t power::return_type_tinfo() const
{
return basis.return_type_tinfo();
}
ex derivative(const symbol & s) const;
ex eval_ncmul(const exvector & v) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
ex expand(unsigned options = 0) const;
// new virtual functions which can be overridden by derived classes
return lh.return_type();
}
-const basic* relational::return_type_tinfo() const
+tinfo_t relational::return_type_tinfo() const
{
GINAC_ASSERT(lh.return_type_tinfo()==rh.return_type_tinfo());
return lh.return_type_tinfo();
ex eval_ncmul(const exvector & v) const;
bool match_same_type(const basic & other) const;
unsigned return_type() const;
- const basic* return_type_tinfo() const;
+ tinfo_t return_type_tinfo() const;
unsigned calchash() const;
// new virtual functions which can be overridden by derived classes
// noncommutativity
unsigned return_type() const { return return_types::commutative; }
- const basic* return_type_tinfo() const { return this; }
+ tinfo_t return_type_tinfo() const { return this; }
protected:
bool is_equal_same_type(const basic & other) const
// symbol
symbol::symbol()
- : 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), domain(domain::complex)
+ : 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);
}
// 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), domain(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, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(default_TeX_name()), ret_type(rt), domain(domain)
+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, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), ret_type(return_types::commutative), domain(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, unsigned domain)
- : inherited(&symbol::tinfo_static), asexinfop(new assigned_ex_info), serial(next_serial++), name(initname), TeX_name(texname), ret_type(rt), domain(domain)
+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(const std::string & initname, const std::string & texname, unsigned domain)
: symbol(initname, texname, domain) { }
-realsymbol::realsymbol(const std::string & initname, unsigned rt, unsigned domain)
- : symbol(initname, rt, 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, unsigned domain)
- : symbol(initname, texname, rt, domain) { }
+realsymbol::realsymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain)
+ : symbol(initname, texname, rt, rtt, domain) { }
//////////
// archiving
// other constructors
public:
explicit symbol(const std::string & initname, unsigned domain = domain::complex);
- symbol(const std::string & initname, unsigned rt, unsigned domain);
symbol(const std::string & initname, const std::string & texname, unsigned domain = domain::complex);
symbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned domain);
+ symbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::complex);
+ symbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::complex);
// functions overriding virtual functions from base classes
public:
ex to_rational(exmap & repl) const;
ex to_polynomial(exmap & repl) const;
unsigned return_type() const { return ret_type; }
+ tinfo_t return_type_tinfo() const { return ret_type_tinfo; }
ex conjugate() const;
protected:
ex derivative(const symbol & s) const;
std::string TeX_name; ///< LaTeX name of this symbol
unsigned domain; ///< domain of symbol, complex (default) or real
unsigned ret_type; ///< value returned by return_type()
+ tinfo_t ret_type_tinfo; ///< value returned by return_type_tinfo()
private:
static unsigned next_serial;
};
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 domain = domain::real);
- realsymbol(const std::string & initname, const std::string & texname, unsigned rt, unsigned domain = domain::real);
+ realsymbol(const std::string & initname, unsigned rt, tinfo_t rtt, unsigned domain = domain::real);
+ realsymbol(const std::string & initname, const std::string & texname, unsigned rt, tinfo_t rtt, unsigned domain = domain::real);
};
if (!ex_to<idx>(i1).get_dim().is_equal(_ex2))
throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
+ if(is_a<wildcard>(i1.op(0))||is_a<wildcard>(i2.op(0)))
+ return indexed(epsilon, antisymmetric2(), i1, i2).hold();
+
return indexed(epsilon, antisymmetric2(), i1, i2);
}
if (!ex_to<idx>(i1).get_dim().is_equal(_ex3))
throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
+ if(is_a<wildcard>(i1.op(0))||is_a<wildcard>(i2.op(0))||is_a<wildcard>(i3.op(0)))
+ return indexed(epsilon, antisymmetric3(), i1, i2, i3).hold();
+
return indexed(epsilon, antisymmetric3(), i1, i2, i3);
}
if (!ex_to<idx>(i1).get_dim().is_equal(_ex4))
throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
+ if(is_a<wildcard>(i1.op(0))||is_a<wildcard>(i2.op(0))||is_a<wildcard>(i3.op(0))||is_a<wildcard>(i4.op(0)))
+ return indexed(pos_sig ? epsilon_pos : epsilon_neg, antisymmetric4(), i1, i2, i3, i4).hold();
+
return indexed(pos_sig ? epsilon_pos : epsilon_neg, antisymmetric4(), i1, i2, i3, i4);
}