74 throw(std::invalid_argument(
"dimension of space must be a positive integer"));
81spinidx::spinidx(
const ex & v,
const ex & d,
bool cov,
bool dot) : inherited(v, d, cov), dotted(dot)
91 inherited::read_archive(
n, sym_lst);
92 n.find_ex(
"value",
value, sym_lst);
93 n.find_ex(
"dim",
dim, sym_lst);
99 inherited::read_archive(
n, sym_lst);
106 inherited::read_archive(
n, sym_lst);
113 inherited::archive(
n);
115 n.add_ex(
"dim",
dim);
120 inherited::archive(
n);
126 inherited::archive(
n);
136 bool need_parens = !(is_exactly_a<numeric>(
value) || is_a<symbol>(
value));
166 c.s << ex_to<numeric>(
value).to_int();
174 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
175 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
192 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
193 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
194 << (
covariant ?
", covariant" :
", contravariant")
223 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
224 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec
225 << (
covariant ?
", covariant" :
", contravariant")
226 << (
dotted ?
", dotted" :
", undotted")
239 return inherited::info(inf);
256 const ex &mapped_value = f(
value);
262 copy->
value = mapped_value;
272 const idx &o =
static_cast<const idx &
>(other);
283 const idx &o =
static_cast<const idx &
>(other);
293 int cmpval = inherited::compare_same_type(other);
312 return inherited::match_same_type(other);
324 int cmpval = inherited::compare_same_type(other);
338 return inherited::match_same_type(other);
374 auto it =
m.
find(*
this);
383 i_copy->
value = it->second;
394 i_copy->
value = subsed_value;
413 const idx &o =
static_cast<const idx &
>(other);
416 if (!is_a<symbol>(
value))
428 return is_exactly_a<numeric>(
dim) || is_exactly_a<numeric>(o.
dim);
439 return inherited::is_dummy_pair_same_type(other);
450 return inherited::is_dummy_pair_same_type(other);
461 i_copy->
dim = new_dim;
503 if (
typeid(i1) !=
typeid(i2))
513 if (!is_a<idx>(e1) || !is_a<idx>(e2))
529 if (itend - it == 1) {
530 if (ex_to<idx>(*it).is_symbolic())
531 out_free.push_back(*it);
541 it = v.begin(); itend = v.end();
543 while (it != itend) {
545 out_dummy.push_back(*
last);
550 if (!it->is_equal(*
last) && ex_to<idx>(*last).is_symbolic())
551 out_free.push_back(*
last);
555 if (ex_to<idx>(*last).is_symbolic())
556 out_free.push_back(*
last);
561 if (dim1.
is_equal(dim2) || dim1 < dim2 || (is_exactly_a<numeric>(dim1) && !is_a<numeric>(dim2)))
563 else if (dim1 > dim2 || (!is_a<numeric>(dim1) && is_exactly_a<numeric>(dim2)))
566 std::ostringstream s;
567 s <<
"minimal_dim(): index dimensions " << dim1 <<
" and " << dim2 <<
" cannot be ordered";
568 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 find(const ex &pattern, exset &found) const
Find all occurrences of a pattern.
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
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.
#define GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(classname, supername, options)
Macro for inclusion in the implementation of each registered class.
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...