+
+ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const
+{
+ if (is_a<indexed>(metric)) {
+ if (symmetrised && !(ex_to<symmetry>(ex_to<indexed>(metric).get_symmetry()).has_symmetry())) {
+ if (is_a<matrix>(metric.op(0))) {
+ return indexed((ex_to<matrix>(metric.op(0)).add(ex_to<matrix>(metric.op(0)).transpose())).mul(numeric(1, 2)),
+ symmetric2(), i, j);
+ } else {
+ return simplify_indexed(indexed(metric.op(0)*_ex1_2, i, j) + indexed(metric.op(0)*_ex1_2, j, i));
+ }
+ } else {
+ return metric.subs(lst(metric.op(1) == i, metric.op(2) == j), subs_options::no_pattern);
+ }
+ } else {
+ exvector indices = metric.get_free_indices();
+ if (symmetrised)
+ return _ex1_2*simplify_indexed(metric.subs(lst(indices[0] == i, indices[1] == j), subs_options::no_pattern)
+ + metric.subs(lst(indices[0] == j, indices[1] == i), subs_options::no_pattern));
+ else
+ return metric.subs(lst(indices[0] == i, indices[1] == j), subs_options::no_pattern);
+ }
+}
+
+bool clifford::same_metric(const ex & other) const
+{
+ ex metr;
+ if (is_a<clifford>(other))
+ metr = ex_to<clifford>(other).get_metric();
+ else
+ metr = other;
+
+ if (is_a<indexed>(metr))
+ return metr.op(0).is_equal(get_metric().op(0));
+ else {
+ exvector indices = metr.get_free_indices();
+ return (indices.size() == 2)
+ && simplify_indexed(get_metric(indices[0], indices[1])-metr).is_zero();
+ }
+}
+