]> www.ginac.de Git - ginac.git/commitdiff
synced to 1.0 (tens4delta and mink4metric replaced by the new index dimension
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 18 Jul 2002 20:08:52 +0000 (20:08 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 18 Jul 2002 20:08:52 +0000 (20:08 +0000)
scheme)

ginac/clifford.cpp
ginac/ex.h
ginac/idx.cpp
ginac/idx.h
ginac/input_lexer.h
ginac/input_lexer.ll
ginac/input_parser.yy
ginac/tensor.cpp
ginac/tensor.h
ginac/tinfos.h

index 2d8904f9272460513f0d796fd195c1ec09ab30b2..b912e42367860e9a64efb5392f79e02fb8b4d41d 100644 (file)
@@ -502,17 +502,19 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
                                return _ex0;
 
                        // Tr gamma5 gamma.mu gamma.nu gamma.rho gamma.sigma = 4I * epsilon(mu, nu, rho, sigma)
+                       // (the epsilon is always 4-dimensional)
                        if (num == 5) {
                                ex b1, i1, b2, i2, b3, i3, b4, i4;
                                base_and_index(e.op(1), b1, i1);
                                base_and_index(e.op(2), b2, i2);
                                base_and_index(e.op(3), b3, i3);
                                base_and_index(e.op(4), b4, i4);
-                               return trONE * I * (eps0123(i1, i2, i3, i4) * b1 * b2 * b3 * b4).simplify_indexed();
+                               return trONE * I * (lorentz_eps(ex_to<idx>(i1).replace_dim(_ex4), ex_to<idx>(i2).replace_dim(_ex4), ex_to<idx>(i3).replace_dim(_ex4), ex_to<idx>(i4).replace_dim(_ex4)) * b1 * b2 * b3 * b4).simplify_indexed();
                        }
 
                        // Tr gamma5 S_2k =
                        //   I/4! * epsilon0123.mu1.mu2.mu3.mu4 * Tr gamma.mu1 gamma.mu2 gamma.mu3 gamma.mu4 S_2k
+                       // (the epsilon is always 4-dimensional)
                        exvector ix(num-1), bv(num-1);
                        for (unsigned i=1; i<num; i++)
                                base_and_index(e.op(i), bv[i-1], ix[i-1]);
@@ -537,7 +539,7 @@ ex dirac_trace(const ex & e, unsigned char rl, const ex & trONE)
                                                                v.push_back(ix[n]);
                                                        }
                                                        int sign = permutation_sign(iv, iv + num);
-                                                       result += sign * eps0123(idx1, idx2, idx3, idx4)
+                                                       result += sign * lorentz_eps(ex_to<idx>(idx1).replace_dim(_ex4), ex_to<idx>(idx2).replace_dim(_ex4), ex_to<idx>(idx3).replace_dim(_ex4), ex_to<idx>(idx4).replace_dim(_ex4))
                                                                * trace_string(v.begin(), num - 4);
                                                }
                                        }
index af5cac31d7cecc73b0f6012260a02dae3f8dbb96..e84decd3f70aabf61a9d4e1d4ee42c6faa9f166e 100644 (file)
@@ -88,10 +88,11 @@ public:
        ex(long i);
        ex(unsigned long i);
        ex(double const d);
+
        /** Construct ex from string and a list of symbols. The input grammar is
-        *  similar to the GiNaC output format. All symbols to be used in the
-        *  expression must be specified in a lst in the second argument. Undefined
-        *  symbols and other parser errors will throw an exception. */
+        *  similar to the GiNaC output format. All symbols and indices to be used
+        *  in the expression must be specified in a lst in the second argument.
+        *  Undefined symbols and other parser errors will throw an exception. */
        ex(const std::string &s, const ex &l);
        
        // non-virtual functions in this class
index bf103f0ff9593e62d795654e84b7b1d5742a5dd5..59c3ebc3eccd67938d8b6d8714201c06fed3a40a 100644 (file)
@@ -26,6 +26,8 @@
 #include "idx.h"
 #include "symbol.h"
 #include "lst.h"
+#include "relational.h"
+#include "operators.h"
 #include "print.h"
 #include "archive.h"
 #include "utils.h"
@@ -301,6 +303,7 @@ int varidx::compare_same_type(const basic & other) const
        // Check variance last so dummy indices will end up next to each other
        if (covariant != o.covariant)
                return covariant ? -1 : 1;
+
        return 0;
 }
 
@@ -311,6 +314,7 @@ bool varidx::match_same_type(const basic & other) const
 
        if (covariant != o.covariant)
                return false;
+
        return inherited::match_same_type(other);
 }
 
@@ -402,8 +406,12 @@ bool idx::is_dummy_pair_same_type(const basic & other) const
        if (!value.is_equal(o.value))
                return false;
 
-       // Also the dimension
-       return dim.is_equal(o.dim);
+       // Dimensions need not be equal but must be comparable (so we can
+       // determine the minimum dimension of contractions)
+       if (dim.is_equal(o.dim))
+               return true;
+
+       return (dim < o.dim || dim > o.dim || (is_a<numeric>(dim) && is_a<symbol>(o.dim)) || (is_a<symbol>(dim) && is_a<numeric>(o.dim)));
 }
 
 bool varidx::is_dummy_pair_same_type(const basic & other) const
@@ -433,6 +441,24 @@ bool spinidx::is_dummy_pair_same_type(const basic & other) const
 // non-virtual functions
 //////////
 
+ex idx::replace_dim(const ex & new_dim) const
+{
+       idx *i_copy = static_cast<idx *>(duplicate());
+       i_copy->dim = new_dim;
+       i_copy->clearflag(status_flags::hash_calculated);
+       return i_copy->setflag(status_flags::dynallocated);
+}
+
+ex idx::minimal_dim(const idx & other) const
+{
+       if (dim.is_equal(other.dim) || dim < other.dim || (is_a<numeric>(dim) && is_a<symbol>(other.dim)))
+               return dim;
+       else if (dim > other.dim || (is_a<symbol>(dim) && is_a<numeric>(other.dim)))
+               return other.dim;
+       else
+               throw (std::runtime_error("idx::minimal_dim: index dimensions cannot be ordered"));
+}
+
 ex varidx::toggle_variance(void) const
 {
        varidx *i_copy = static_cast<varidx *>(duplicate());
index b648c62ac74357466244639940dbfd87fcd7a942..0b31696c772840c347aa0fad1aa9e71099de93c7 100644 (file)
@@ -85,6 +85,13 @@ public:
        /** Check whether the dimension is symbolic. */
        bool is_dim_symbolic(void) const {return !is_exactly_a<numeric>(dim);}
 
+       /** Make a new index with the same value but a different dimension. */
+       ex replace_dim(const ex & new_dim) const;
+
+       /** Return the minimum of the dimensions of this and another index.
+        *  If this is undecidable, throw an exception. */
+       ex minimal_dim(const idx & other) const;
+
 protected:
        ex value; /**< Expression that constitutes the index (numeric or symbolic name) */
        ex dim;   /**< Dimension of space (can be symbolic or numeric) */
index b7cc3c01af4da7ac2d7f861e7864ff21661077cc..ed3f94c63a1ddfb697df87cc8285b62657d53928 100644 (file)
@@ -50,6 +50,9 @@ class ex;
 /** Set the input string to be parsed by ginac_yyparse() (used internally). */
 extern void set_lexer_string(const std::string &s);
 
+/** Get name of symbol/index (used internally). */
+extern std::string get_symbol_name(const ex & s);
+
 /** Set the list of predefined symbols for the lexer (used internally). */
 extern void set_lexer_symbols(ex l);
 
index 6396248d1fe23eb94233d8650aa50379312e14c0..4a5a65015e31ac983b64a92a18b1e8fb7457f694 100644 (file)
@@ -39,6 +39,7 @@
 #include "numeric.h"
 #include "symbol.h"
 #include "lst.h"
+#include "idx.h"
 
 using namespace GiNaC;
 namespace GiNaC {
@@ -47,7 +48,7 @@ namespace GiNaC {
 
 } // namespace GiNaC
 
-// Table of all used symbols
+// Table of all used symbols/indices
 struct sym_def {
        sym_def() : predefined(false) {}
        sym_def(const ex &s, bool predef) : sym(s), predefined(predef) {}
@@ -166,22 +167,34 @@ void set_lexer_string(const std::string &s)
        curr_pos = 0;
 }
 
-// Set the list of predefined symbols
+// Get name of symbol/index
+std::string get_symbol_name(const ex & s)
+{
+       if (is_a<symbol>(s))
+               return ex_to<symbol>(s).get_name();
+       else if (is_a<idx>(s) && is_a<symbol>(s.op(0)))
+               return ex_to<symbol>(s.op(0)).get_name();
+       else
+               throw (std::runtime_error("get_symbol_name(): unexpected expression type"));
+}
+
+// Set the list of predefined symbols/indices
 void set_lexer_symbols(ex l)
 {
        syms.clear();
        if (!is_exactly_a<lst>(l))
                return;
        for (unsigned i=0; i<l.nops(); i++) {
-               if (is_exactly_a<symbol>(l.op(i)))
-                       syms[ex_to<symbol>(l.op(i)).get_name()] = sym_def(l.op(i), true);
+               const ex &o = l.op(i);
+               if (is_a<symbol>(o) || (is_a<idx>(o) && is_a<symbol>(o.op(0))))
+                       syms[get_symbol_name(o)] = sym_def(o, true);
        }
 }
 
-// Check whether symbol was predefined
+// Check whether symbol/index was predefined
 bool is_lexer_symbol_predefined(const ex &s)
 {
-       sym_tab::const_iterator i = syms.find(ex_to<symbol>(s).get_name());
+       sym_tab::const_iterator i = syms.find(get_symbol_name(s));
        if (i == syms.end())
                return false;
        else
index 778b8347da3c88a239b8c83a4a4fa4a123ba2e18..ecdc317e6ee08dd706c8228887c15ee94cbc4203 100644 (file)
@@ -37,6 +37,8 @@
 #include "lst.h"
 #include "power.h"
 #include "exprseq.h"
+#include "idx.h"
+#include "indexed.h"
 #include "matrix.h"
 #include "inifcns.h"
 
@@ -49,6 +51,9 @@ ex parsed_ex;
 
 // Last error message returned by parser
 static std::string parser_error;
+
+// Prototypes
+ex attach_index(const ex & base, ex i, bool covariant);
 %}
 
 /* Tokens (T_LITERAL means a literal value returned by the parser, but not
@@ -63,6 +68,7 @@ static std::string parser_error;
 %left '*' '/' '%'
 %nonassoc NEG
 %right '^'
+%left '.' '~'
 %nonassoc '!'
 
 %start input
@@ -90,12 +96,12 @@ exp : T_NUMBER              {$$ = $1;}
                if (is_lexer_symbol_predefined($1))
                        $$ = $1.eval();
                else
-                       throw (std::runtime_error("unknown symbol '" + ex_to<symbol>($1).get_name() + "'"));
+                       throw (std::runtime_error("unknown symbol '" + get_symbol_name($1) + "'"));
        }
        | T_LITERAL             {$$ = $1;}
        | T_DIGITS              {$$ = $1;}
        | T_SYMBOL '(' exprseq ')' {
-               std::string n = ex_to<symbol>($1).get_name();
+               std::string n = get_symbol_name($1);
                if (n == "sqrt") {
                        if ($3.nops() != 1)
                                throw (std::runtime_error("too many arguments to sqrt()"));
@@ -118,6 +124,8 @@ exp : T_NUMBER              {$$ = $1;}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = pow($1, $3);}
+       | exp '.' exp           {$$ = attach_index($1, $3, true);}
+       | exp '~' exp           {$$ = attach_index($1, $3, false);}
        | exp '!'               {$$ = factorial($1);}
        | '(' exp ')'           {$$ = $2;}
        | '{' list_or_empty '}' {$$ = $2;}
@@ -150,6 +158,30 @@ row        : exp                   {$$ = lst($1);}
  */
 
 %%
+// Attach index to expression
+ex attach_index(const ex & base, ex i, bool covariant)
+{
+       // Toggle index variance if necessary
+       if (is_a<varidx>(i)) {
+               const varidx &vi = ex_to<varidx>(i);
+               if (vi.is_covariant() != covariant)
+                       i = vi.toggle_variance();
+       } else if (!covariant)
+               throw (std::runtime_error("index '" + get_symbol_name(i) + "' is not a varidx and cannot be contravariant"));
+
+       // Add index to an existing indexed object, or create a new indexed
+       // object if there are no indices yet
+       if (is_a<indexed>(base)) {
+               const ex &b = base.op(0);
+               exvector iv;
+               for (unsigned n=1; n<base.nops(); n++)
+                       iv.push_back(base.op(n));
+               iv.push_back(i);
+               return indexed(b, iv);
+       } else
+               return indexed(base, i);
+}
+
 // Get last error encountered by parser
 std::string get_parser_error(void)
 {
index a4ae63e05a70cbd5e5d6ae3461399123dcf7c6dd..d6ab5a1f658b0c1819f38f8f5b798e0565f3498d 100644 (file)
@@ -41,10 +41,8 @@ namespace GiNaC {
 
 GINAC_IMPLEMENT_REGISTERED_CLASS(tensor, basic)
 GINAC_IMPLEMENT_REGISTERED_CLASS(tensdelta, tensor)
-GINAC_IMPLEMENT_REGISTERED_CLASS(tens4delta, tensor)
 GINAC_IMPLEMENT_REGISTERED_CLASS(tensmetric, tensor)
 GINAC_IMPLEMENT_REGISTERED_CLASS(minkmetric, tensmetric)
-GINAC_IMPLEMENT_REGISTERED_CLASS(mink4metric, tensor)
 GINAC_IMPLEMENT_REGISTERED_CLASS(spinmetric, tensmetric)
 GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor)
 
@@ -54,12 +52,10 @@ GINAC_IMPLEMENT_REGISTERED_CLASS(tensepsilon, tensor)
 
 DEFAULT_CTORS(tensor)
 DEFAULT_CTORS(tensdelta)
-DEFAULT_CTORS(tens4delta)
 DEFAULT_CTORS(tensmetric)
 DEFAULT_COPY(spinmetric)
 DEFAULT_DESTROY(spinmetric)
 DEFAULT_DESTROY(minkmetric)
-DEFAULT_DESTROY(mink4metric)
 DEFAULT_DESTROY(tensepsilon)
 
 minkmetric::minkmetric() : pos_sig(false)
@@ -67,11 +63,6 @@ minkmetric::minkmetric() : pos_sig(false)
        tinfo_key = TINFO_minkmetric;
 }
 
-mink4metric::mink4metric() : pos_sig(false)
-{
-       tinfo_key = TINFO_mink4metric;
-}
-
 spinmetric::spinmetric()
 {
        tinfo_key = TINFO_spinmetric;
@@ -82,29 +73,18 @@ minkmetric::minkmetric(bool ps) : pos_sig(ps)
        tinfo_key = TINFO_minkmetric;
 }
 
-mink4metric::mink4metric(bool ps) : pos_sig(ps)
-{
-       tinfo_key = TINFO_mink4metric;
-}
-
 void minkmetric::copy(const minkmetric & other)
 {
        inherited::copy(other);
        pos_sig = other.pos_sig;
 }
 
-void mink4metric::copy(const mink4metric & other)
-{
-       inherited::copy(other);
-       pos_sig = other.pos_sig;
-}
-
-tensepsilon::tensepsilon() : minkowski(false), pos_sig(false), four_dim(false)
+tensepsilon::tensepsilon() : minkowski(false), pos_sig(false)
 {
        tinfo_key = TINFO_tensepsilon;
 }
 
-tensepsilon::tensepsilon(bool mink, bool ps, bool fd) : minkowski(mink), pos_sig(ps), four_dim(fd)
+tensepsilon::tensepsilon(bool mink, bool ps) : minkowski(mink), pos_sig(ps)
 {
        tinfo_key = TINFO_tensepsilon;
 }
@@ -114,7 +94,6 @@ void tensepsilon::copy(const tensepsilon & other)
        inherited::copy(other);
        minkowski = other.minkowski;
        pos_sig = other.pos_sig;
-       four_dim = other.four_dim;
 }
 
 //////////
@@ -123,11 +102,9 @@ void tensepsilon::copy(const tensepsilon & other)
 
 DEFAULT_ARCHIVING(tensor)
 DEFAULT_ARCHIVING(tensdelta)
-DEFAULT_ARCHIVING(tens4delta)
 DEFAULT_ARCHIVING(tensmetric)
 DEFAULT_ARCHIVING(spinmetric)
 DEFAULT_UNARCHIVE(minkmetric)
-DEFAULT_UNARCHIVE(mink4metric)
 DEFAULT_UNARCHIVE(tensepsilon)
 
 minkmetric::minkmetric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
@@ -141,22 +118,10 @@ void minkmetric::archive(archive_node &n) const
        n.add_bool("pos_sig", pos_sig);
 }
 
-mink4metric::mink4metric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
-{
-       n.find_bool("pos_sig", pos_sig);
-}
-
-void mink4metric::archive(archive_node &n) const
-{
-       inherited::archive(n);
-       n.add_bool("pos_sig", pos_sig);
-}
-
 tensepsilon::tensepsilon(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
 {
        n.find_bool("minkowski", minkowski);
        n.find_bool("pos_sig", pos_sig);
-       n.find_bool("4dim", four_dim);
 }
 
 void tensepsilon::archive(archive_node &n) const
@@ -164,7 +129,6 @@ void tensepsilon::archive(archive_node &n) const
        inherited::archive(n);
        n.add_bool("minkowski", minkowski);
        n.add_bool("pos_sig", pos_sig);
-       n.add_bool("4dim", four_dim);
 }
 
 //////////
@@ -173,7 +137,6 @@ void tensepsilon::archive(archive_node &n) const
 
 DEFAULT_COMPARE(tensor)
 DEFAULT_COMPARE(tensdelta)
-DEFAULT_COMPARE(tens4delta)
 DEFAULT_COMPARE(tensmetric)
 DEFAULT_COMPARE(spinmetric)
 
@@ -188,17 +151,6 @@ int minkmetric::compare_same_type(const basic & other) const
                return inherited::compare_same_type(other);
 }
 
-int mink4metric::compare_same_type(const basic & other) const
-{
-       GINAC_ASSERT(is_a<mink4metric>(other));
-       const mink4metric &o = static_cast<const mink4metric &>(other);
-
-       if (pos_sig != o.pos_sig)
-               return pos_sig ? -1 : 1;
-       else
-               return inherited::compare_same_type(other);
-}
-
 int tensepsilon::compare_same_type(const basic & other) const
 {
        GINAC_ASSERT(is_a<tensepsilon>(other));
@@ -208,17 +160,13 @@ int tensepsilon::compare_same_type(const basic & other) const
                return minkowski ? -1 : 1;
        else if (pos_sig != o.pos_sig)
                return pos_sig ? -1 : 1;
-       else if (four_dim != o.four_dim)
-               return four_dim ? -1 : 1;
        else
                return inherited::compare_same_type(other);
 }
 
 DEFAULT_PRINT_LATEX(tensdelta, "delta", "\\delta")
-DEFAULT_PRINT_LATEX(tens4delta, "delta4", "{\\delta^{(4)}}")
 DEFAULT_PRINT(tensmetric, "g")
 DEFAULT_PRINT_LATEX(minkmetric, "eta", "\\eta")
-DEFAULT_PRINT_LATEX(mink4metric, "eta4", "{\\eta^{(4)}}")
 DEFAULT_PRINT_LATEX(spinmetric, "eps", "\\varepsilon")
 DEFAULT_PRINT_LATEX(tensepsilon, "eps", "\\varepsilon")
 
@@ -232,47 +180,19 @@ ex tensdelta::eval_indexed(const basic & i) const
        const idx & i1 = ex_to<idx>(i.op(1));
        const idx & i2 = ex_to<idx>(i.op(2));
 
-       // Trace of delta tensor is the dimension of the space
-       if (is_dummy_pair(i1, i2))
-               return i1.get_dim();
-
-       // Numeric evaluation
-       if (static_cast<const indexed &>(i).all_index_values_are(info_flags::integer)) {
-               int n1 = ex_to<numeric>(i1.get_value()).to_int(), n2 = ex_to<numeric>(i2.get_value()).to_int();
-               if (n1 == n2)
-                       return _ex1;
-               else
-                       return _ex0;
+       // Trace of delta tensor is the (effective) dimension of the space
+       if (is_dummy_pair(i1, i2)) {
+               try {
+                       return i1.minimal_dim(i2);
+               } catch (std::exception &e) {
+                       return i.hold();
+               }
        }
 
-       // No further simplifications
-       return i.hold();
-}
-
-/** Automatic symbolic evaluation of an indexed 4-dimensional delta tensor. */
-ex tens4delta::eval_indexed(const basic & i) const
-{
-       GINAC_ASSERT(is_a<indexed>(i));
-       GINAC_ASSERT(i.nops() == 3);
-       GINAC_ASSERT(is_a<tens4delta>(i.op(0)));
-
-       const idx & i1 = ex_to<idx>(i.op(1));
-       const idx & i2 = ex_to<idx>(i.op(2));
-
-       // Trace of 4-dimensional delta tensor is four
-       if (is_dummy_pair(i1, i2))
-               return _ex4;
-
-       // 4-dimensional delta tensor with numeric index dimension of four or
-       // less gets replaced by ordinary delta tensor
-       if (i1.get_dim().is_equal(i2.get_dim()) && is_a<numeric>(i1.get_dim())
-        && ex_to<numeric>(i1.get_dim()).to_int() <= 4)
-               return indexed(tensdelta(), sy_symm(), i.op(1), i.op(2));
-
        // Numeric evaluation
        if (static_cast<const indexed &>(i).all_index_values_are(info_flags::integer)) {
                int n1 = ex_to<numeric>(i1.get_value()).to_int(), n2 = ex_to<numeric>(i2.get_value()).to_int();
-               if (n1 == n2 && n1 < 4)
+               if (n1 == n2)
                        return _ex1;
                else
                        return _ex0;
@@ -330,45 +250,6 @@ ex minkmetric::eval_indexed(const basic & i) const
        return inherited::eval_indexed(i);
 }
 
-/** Automatic symbolic evaluation of an indexed 4-dimensional Lorentz metric
- *  tensor. */
-ex mink4metric::eval_indexed(const basic & i) const
-{
-       GINAC_ASSERT(is_a<indexed>(i));
-       GINAC_ASSERT(i.nops() == 3);
-       GINAC_ASSERT(is_a<mink4metric>(i.op(0)));
-       GINAC_ASSERT(is_a<varidx>(i.op(1)));
-       GINAC_ASSERT(is_a<varidx>(i.op(2)));
-
-       const varidx & i1 = ex_to<varidx>(i.op(1));
-       const varidx & i2 = ex_to<varidx>(i.op(2));
-
-       // 4-dimensional Lorentz metric tensor with numeric index dimension of
-       // four or less gets replaced by ordinary Lorentz metric tensor
-       if (i1.get_dim().is_equal(i2.get_dim()) && is_a<numeric>(i1.get_dim())
-        && ex_to<numeric>(i1.get_dim()).to_int() <= 4)
-               return indexed(minkmetric(pos_sig), sy_symm(), i.op(1), i.op(2));
-
-       // A metric tensor with one covariant and one contravariant index gets
-       // replaced by a delta tensor
-       if (i1.is_covariant() != i2.is_covariant())
-               return indexed(tens4delta(), sy_symm(), i.op(1), i.op(2));
-
-       // Numeric evaluation
-       if (static_cast<const indexed &>(i).all_index_values_are(info_flags::nonnegint)) {
-               int n1 = ex_to<numeric>(i1.get_value()).to_int(), n2 = ex_to<numeric>(i2.get_value()).to_int();
-               if (n1 != n2 || n1 > 3)
-                       return _ex0;
-               else if (n1 == 0)
-                       return pos_sig ? _ex_1 : _ex1;
-               else
-                       return pos_sig ? _ex1 : _ex_1;
-       }
-
-       // No further simplifications
-       return i.hold();
-}
-
 /** Automatic symbolic evaluation of an indexed metric tensor. */
 ex spinmetric::eval_indexed(const basic & i) const
 {
@@ -458,9 +339,15 @@ again:
 
                                // Contraction found, remove this tensor and substitute the
                                // index in the second object
-                               *self = _ex1;
-                               *other = other->subs(other_idx == *free_idx);
-                               return true;
+                               try {
+                                       // minimal_dim() throws an exception when index dimensions are not comparable
+                                       ex min_dim = self_idx->minimal_dim(other_idx);
+                                       *self = _ex1;
+                                       *other = other->subs(other_idx == free_idx->replace_dim(min_dim));
+                                       return true;
+                               } catch (std::exception &e) {
+                                       return false;
+                               }
                        }
                }
        }
@@ -490,23 +377,6 @@ bool tensdelta::contract_with(exvector::iterator self, exvector::iterator other,
        return replace_contr_index(self, other);
 }
 
-/** Contraction of an indexed 4-dimensional delta tensor with something else. */
-bool tens4delta::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
-{
-       GINAC_ASSERT(is_a<indexed>(*self));
-       GINAC_ASSERT(is_a<indexed>(*other));
-       GINAC_ASSERT(self->nops() == 3);
-       GINAC_ASSERT(is_a<tens4delta>(self->op(0)));
-
-       // Only contract with 4-dimensional delta, metric and epsilon tensors
-       if (!(is_a<tens4delta>(other->op(0)) || is_a<mink4metric>(other->op(0)) || is_a<tensepsilon>(other->op(0))))
-               return false;
-
-       // Replace the dummy index with this tensor's other index and remove
-       // the tensor
-       return replace_contr_index(self, other);
-}
-
 /** Contraction of an indexed metric tensor with something else. */
 bool tensmetric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
 {
@@ -525,24 +395,6 @@ bool tensmetric::contract_with(exvector::iterator self, exvector::iterator other
        return replace_contr_index(self, other);
 }
 
-/** Contraction of an indexed 4-dimensional Lorentz metric tensor with something else. */
-bool mink4metric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
-{
-       GINAC_ASSERT(is_a<indexed>(*self));
-       GINAC_ASSERT(is_a<indexed>(*other));
-       GINAC_ASSERT(self->nops() == 3);
-       GINAC_ASSERT(is_a<mink4metric>(self->op(0)));
-
-       // Only contract with 4-dimensional metric and epsilon tensors
-       if (!(is_a<mink4metric>(other->op(0)) || is_a<tensepsilon>(other->op(0))))
-               return false;
-
-       // Replace the dummy index with this tensor's other index and remove
-       // the tensor
-       return replace_contr_index(self, other);
-}
-
-
 /** Contraction of an indexed spinor metric with something else. */
 bool spinmetric::contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const
 {
@@ -636,9 +488,7 @@ bool tensepsilon::contract_with(exvector::iterator self, exvector::iterator othe
                matrix M(num, num);
                for (int i=0; i<num; i++) {
                        for (int j=0; j<num; j++) {
-                               if (four_dim)
-                                       M(i, j) = indexed(mink4metric(pos_sig), sy_symm(), self->op(i+1), other->op(j+1));
-                               else if (minkowski)
+                               if (minkowski)
                                        M(i, j) = lorentz_g(self->op(i+1), other->op(j+1), pos_sig);
                                else
                                        M(i, j) = metric_tensor(self->op(i+1), other->op(j+1));
@@ -736,19 +586,7 @@ ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool
        if (!ex_to<idx>(i1).get_dim().is_equal(_ex4))
                throw(std::runtime_error("index dimension of epsilon tensor must match number of indices"));
 
-       return indexed(tensepsilon(true, pos_sig, false), sy_anti(), i1, i2, i3, i4);
-}
-
-ex eps0123(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig)
-{
-       if (!is_a<varidx>(i1) || !is_a<varidx>(i2) || !is_a<varidx>(i3) || !is_a<varidx>(i4))
-               throw(std::invalid_argument("indices of epsilon tensor must be of type varidx"));
-
-       ex dim = ex_to<idx>(i1).get_dim();
-       if (dim.is_equal(4))
-               return lorentz_eps(i1, i2, i3, i4, pos_sig);
-       else
-               return indexed(tensepsilon(true, pos_sig, true), sy_anti(), i1, i2, i3, i4);
+       return indexed(tensepsilon(true, pos_sig), sy_anti(), i1, i2, i3, i4);
 }
 
 } // namespace GiNaC
index 2fa8e661ff249b8fdbaf82c90ba41db8f81716a5..7774f4ba991a35e3237b6bcfb50546c041d0e23c 100644 (file)
@@ -120,46 +120,6 @@ public:
 };
 
 
-/** This class represents a 4-dimensional delta tensor embedded in a
- *  higher-dimensional space. Its matrix representation is
- *  diag(1,1,1,1,0,0...). */
-class tens4delta : public tensor
-{
-       GINAC_DECLARE_REGISTERED_CLASS(tens4delta, tensor)
-
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
-       ex eval_indexed(const basic & i) const;
-       bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
-};
-
-
-/** This class represents a 4-dimensional Minkowski tensor embedded in
- *  a higher-dimensional space (so it's not really a metric for that space;
- *  that's why this is not a subclass of tensmetric). Its matrix representation
- *  is diag(1,-1,-1,-1,0,0,...) or diag(-1,1,1,1,0,0,...). */
-class mink4metric : public tensor
-{
-       GINAC_DECLARE_REGISTERED_CLASS(mink4metric, tensor)
-
-       // other constructors
-public:
-       /** Construct Lorentz metric tensor with given signature. */
-       mink4metric(bool pos_sig);
-
-       // functions overriding virtual functions from base classes
-public:
-       void print(const print_context & c, unsigned level = 0) const;
-       ex eval_indexed(const basic & i) const;
-       bool contract_with(exvector::iterator self, exvector::iterator other, exvector & v) const;
-
-       // member variables
-private:
-       bool pos_sig; /**< If true, the metric is diag(-1,1,...). Otherwise it is diag(1,-1,...). */
-};
-
-
 /** This class represents the totally antisymmetric epsilon tensor. If
  *  indexed, all indices must be of the same type and their number must
  *  be equal to the dimension of the index space. */
@@ -169,7 +129,7 @@ class tensepsilon : public tensor
 
        // other constructors
 public:
-       tensepsilon(bool minkowski, bool pos_sig, bool four_dim);
+       tensepsilon(bool minkowski, bool pos_sig);
 
        // functions overriding virtual functions from base classes
 public:
@@ -181,7 +141,6 @@ public:
 private:
        bool minkowski; /**< If true, tensor is in Minkowski-type space. Otherwise it is in a Euclidean space. */
        bool pos_sig;   /**< If true, the metric is assumed to be diag(-1,1,1...). Otherwise it is diag(1,-1,-1,...). This is only relevant if minkowski = true. */
-       bool four_dim;  /**< If true, this is a four-dimensional object embedded in a higher-dimensional space */
 };
 
 
@@ -254,18 +213,6 @@ ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3);
  *  @return newly constructed epsilon tensor */
 ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
 
-/** Create an epsilon tensor in a 4-dimensional projection of a D-dimensional
- *  Minkowski space. It vanishes whenever one of the indices is not in the
- *  set {0, 1, 2, 3}.
- *
- *  @param i1 First index
- *  @param i2 Second index
- *  @param i3 Third index
- *  @param i4 Fourth index
- *  @param pos_sig Whether the signature of the metric is positive
- *  @return newly constructed epsilon tensor */
-ex eps0123(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig = false);
-
 } // namespace GiNaC
 
 #endif // ndef __GINAC_TENSOR_H__
index d02caa83a96a910aaddde07321c7cd1571fed6ee..03b7315e0a2eab78ba4ab9a02062167015e9d004 100644 (file)
@@ -75,8 +75,6 @@ const unsigned TINFO_tensmetric    = 0x000e1002U;
 const unsigned TINFO_minkmetric    = 0x000e2001U;
 const unsigned TINFO_spinmetric    = 0x000e2002U;
 const unsigned TINFO_tensepsilon   = 0x000e1003U;
-const unsigned TINFO_tens4delta    = 0x000e1004U;
-const unsigned TINFO_mink4metric   = 0x000e1005U;
 const unsigned TINFO_su3one        = 0x000e1008U;
 const unsigned TINFO_su3t          = 0x000e1009U;
 const unsigned TINFO_su3f          = 0x000e100aU;