[GiNaC-devel] [BUG] clifford::op() versus tensor::replace_contr_index
Sheplyakov Alexei
varg at theor.jinr.ru
Wed Oct 18 16:40:22 CEST 2006
Dear all,
I've tried making ex_to<T> functions [more] type-safe, like this:
diff --git a/ginac/ex.h b/ginac/ex.h
index 3070b7a..79f872b 100644
--- a/ginac/ex.h
+++ b/ginac/ex.h
@@ -949,7 +949,8 @@ inline bool is_exactly_a(const ex &obj)
template <class T>
inline const T &ex_to(const ex &e)
{
- GINAC_ASSERT(is_a<T>(e));
+ if (__builtin_expect(! is_a<T>(e), 0))
+ throw std::bad_cast();
return static_cast<const T &>(*e.bp);
}
and got failure in exam_clifford (to be more specific, last expression
in clifford_check4 triggered bad_cast). I've found a simple[r] example
which fails in the same way:
#include <iostream>
#include <stdexcept>
#include "ginac.h"
using namespace GiNaC;
int main(int argc, char** argv)
{
symbol d("D");
varidx mu(symbol("mu"), d),
nu(symbol("nu"), d);
ex e = lorentz_g(mu, nu)*dirac_gamma(nu.toggle_variance());
e = e.simplify_indexed();
return 0;
}
The reason of this error seems to be inconsistency between clifford::op
and tensor::replace_contr_index. tensor::replace_contr_index expects
any subexpression of `indexed' referenced via op() to be `idx' (see
tensor.cpp:398). On the other hand, `clifford' objects make their
representation label accessible via op(), so this assumption is incorrect.
So, the questions are:
1) Any ideas how to fix this?
2) In general, is it OK for class derived from indexed return something
which is *not* idx (or derived from it) via op()?
Best regards,
Alexei
--
All science is either physics or stamp collecting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
URL: <http://www.ginac.de/pipermail/ginac-devel/attachments/20061018/92ce178e/attachment.sig>
More information about the GiNaC-devel
mailing list