76 throw(std::invalid_argument(
"dimension of space must be a positive integer"));
83spinidx::spinidx(
const ex & v,
const ex & d,
bool cov,
bool dot) : inherited(v, d, cov), dotted(dot)
93 inherited::read_archive(
n, sym_lst);
94 n.find_ex(
"value",
value, sym_lst);
95 n.find_ex(
"dim",
dim, sym_lst);
101 inherited::read_archive(
n, sym_lst);
108 inherited::read_archive(
n, sym_lst);
115 inherited::archive(
n);
117 n.add_ex(
"dim",
dim);
122 inherited::archive(
n);
128 inherited::archive(
n);
138 bool need_parens = !(is_exactly_a<numeric>(
value) || is_a<symbol>(
value));
168 c.s << ex_to<numeric>(
value).to_int();
176 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
177 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
194 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
195 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
196 << (
covariant ?
", covariant" :
", contravariant")
225 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
226 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
227 << (
covariant ?
", covariant" :
", contravariant")
228 << (
dotted ?
", dotted" :
", undotted")
241 return inherited::info(inf);
258 const ex &mapped_value = f(
value);
264 copy->
value = mapped_value;
274 const idx &o =
static_cast<const idx &
>(other);
285 const idx &o =
static_cast<const idx &
>(other);
295 int cmpval = inherited::compare_same_type(other);
314 return inherited::match_same_type(other);
326 int cmpval = inherited::compare_same_type(other);
340 return inherited::match_same_type(other);
376 auto it =
m.find(*
this);
385 i_copy->
value = it->second;
396 i_copy->
value = subsed_value;
415 const idx &o =
static_cast<const idx &
>(other);
418 if (!is_a<symbol>(
value))
430 return is_exactly_a<numeric>(
dim) || is_exactly_a<numeric>(o.
dim);
441 return inherited::is_dummy_pair_same_type(other);
452 return inherited::is_dummy_pair_same_type(other);
463 i_copy->
dim = new_dim;
505 if (
typeid(i1) !=
typeid(i2))
515 if (!is_a<idx>(e1) || !is_a<idx>(e2))
531 if (itend - it == 1) {
532 if (ex_to<idx>(*it).is_symbolic())
533 out_free.push_back(*it);
543 it = v.begin(); itend = v.end();
545 while (it != itend) {
547 out_dummy.push_back(*
last);
552 if (!it->is_equal(*
last) && ex_to<idx>(*last).is_symbolic())
553 out_free.push_back(*
last);
557 if (ex_to<idx>(*last).is_symbolic())
558 out_free.push_back(*
last);
563 if (dim1.
is_equal(dim2) || dim1 < dim2 || (is_exactly_a<numeric>(dim1) && !is_a<numeric>(dim2)))
565 else if (dim1 > dim2 || (!is_a<numeric>(dim1) && is_exactly_a<numeric>(dim2)))
568 std::ostringstream s;
569 s <<
"minimal_dim(): index dimensions " << dim1 <<
" and " << dim2 <<
" cannot be ordered";
570 throw (std::runtime_error(s.str()));
Archiving of GiNaC expressions.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
const basic & clearflag(unsigned f) const
Clear some status_flags.
const basic & setflag(unsigned f) const
Set some status_flags.
unsigned hashvalue
hash value
unsigned flags
of type status_flags
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
virtual basic * duplicate() const
Create a clone of this object on the heap.
Wrapper template for making GiNaC classes out of STL containers.
Lightweight wrapper for GiNaC's symbolic objects.
bool is_equal(const ex &other) const
ex subs(const exmap &m, unsigned options=0) const
bool info(unsigned inf) const
int compare(const ex &other) const
void print(const print_context &c, unsigned level=0) const
Print expression to stream.
This class holds one index of an indexed object.
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only,...
void print_index(const print_context &c, unsigned level) const
ex derivative(const symbol &s) const override
Implementation of ex::diff() for an index always returns 0.
ex dim
Dimension of space (can be symbolic or numeric)
idx(const ex &v, const ex &dim)
Construct index with given value and dimension.
void do_print_csrc(const print_csrc &c, unsigned level) const
bool is_dim_numeric() const
Check whether the dimension is numeric.
unsigned calchash() const override
Compute the hash value of an object and if it makes sense to store it in the objects status_flags,...
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
ex replace_dim(const ex &new_dim) const
Make a new index with the same value but a different dimension.
ex op(size_t i) const override
Return operand/member at position i.
ex value
Expression that constitutes the index (numeric or symbolic name)
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
virtual bool is_dummy_pair_same_type(const basic &other) const
Check whether the index forms a dummy index pair with another index of the same type.
bool info(unsigned inf) const override
Information about the object.
void do_print_latex(const print_latex &c, unsigned level) const
size_t nops() const override
Number of operands/members.
void do_print_tree(const print_tree &c, unsigned level) const
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
ex minimal_dim(const idx &other) const
Return the minimum of the dimensions of this and another index.
void do_print(const print_context &c, unsigned level) const
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
ex evalf() const override
By default, basic::evalf would evaluate the index value but we don't want a.1 to become a.
Base class for print_contexts.
Base context for C source output.
Context for latex-parsable output.
@ print_index_dimensions
print the dimensions of indices
Context for tree-like output for debugging.
This class holds a spinor index that can be dotted or undotted and that also has a variance.
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
void do_print_latex(const print_latex &c, unsigned level) const
void do_print(const print_context &c, unsigned level) const
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
spinidx(const ex &v, const ex &dim=2, bool covariant=false, bool dotted=false)
Construct index with given value, dimension, variance and dot.
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
ex toggle_dot() const
Make a new index with the same value and variance but the opposite dottedness.
bool is_dummy_pair_same_type(const basic &other) const override
Check whether the index forms a dummy index pair with another index of the same type.
void do_print_tree(const print_tree &c, unsigned level) const
ex toggle_variance_dot() const
Make a new index with the same value but opposite variance and dottedness.
@ evaluated
.eval() has already done its job
@ hash_calculated
.calchash() has already done its job
This class holds an index with a variance (co- or contravariant).
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
bool is_dummy_pair_same_type(const basic &other) const override
Check whether the index forms a dummy index pair with another index of the same type.
varidx(const ex &v, const ex &dim, bool covariant=false)
Construct index with given value, dimension and variance.
void do_print(const print_context &c, unsigned level) const
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
bool match_same_type(const basic &other) const override
Returns true if the attributes of two objects are similar enough for a match.
bool covariant
x.mu, default is contravariant: x~mu
void do_print_tree(const print_tree &c, unsigned level) const
ex toggle_variance() const
Make a new index with the same value but the opposite variance.
Interface to GiNaC's indices.
Definition of GiNaC's lst.
ex minimal_dim(const ex &dim1, const ex &dim2)
Return the minimum of two index dimensions.
std::map< ex, ex, ex_is_less > exmap
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
bool is_dummy_pair(const idx &i1, const idx &i2)
Check whether two indices form a dummy pair.
print_func< print_context >(&varidx::do_print). print_func< print_latex >(&varidx
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(add, expairseq, print_func< print_context >(&add::do_print). print_func< print_latex >(&add::do_print_latex). print_func< print_csrc >(&add::do_print_csrc). print_func< print_tree >(&add::do_print_tree). print_func< print_python_repr >(&add::do_print_python_repr)) add
static unsigned make_hash_seed(const std::type_info &tinfo)
We need a hash function which gives different values for objects of different types.
unsigned rotate_left(unsigned n)
Rotate bits of unsigned value by one bit to the left.
void shaker_sort(It first, It last, Cmp comp, Swap swapit)
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func< print_context >(&lst::do_print). print_func< print_tree >(&lst::do_print_tree)) template<> bool lst GINAC_BIND_UNARCHIVER(lst)
Specialization of container::info() for lst.
void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector &out_free, exvector &out_dummy)
Given a vector of indices, split them into two vectors, one containing the free indices,...
std::vector< ex > exvector
Interface to GiNaC's overloaded operators.
Interface to relations between expressions.
Function object for map().
Interface to GiNaC's symbolic objects.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...