- if (is_a<indexed>(metr))
- return clifford(unit, mu, metr.op(0), rl);
- else if(is_a<tensmetric>(metr) || is_a<matrix>(metr))
- return clifford(unit, mu, metr, rl);
- else
- throw(std::invalid_argument("metric for Clifford unit must be of type indexed, tensormetric or matrix"));
+ if (ex_to<idx>(mu).is_symbolic() && !is_a<varidx>(mu))
+ throw(std::invalid_argument("clifford_unit(): symbolic index of Clifford unit must be of type varidx (not idx)"));
+
+ if (is_a<indexed>(metr)) {
+ exvector indices = ex_to<indexed>(metr).get_indices();
+ if ((indices.size() == 2) && is_a<varidx>(indices[0]) && is_a<varidx>(indices[1])) {
+ return clifford(unit, mu, metr, rl, anticommuting);
+ } else {
+ throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be indexed exactly by two indices of same type as the given index"));
+ }
+ } else if (is_a<tensor>(metr)) {
+ static varidx xi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim()),
+ chi((new symbol)->setflag(status_flags::dynallocated), ex_to<varidx>(mu).get_dim());
+ return clifford(unit, mu, indexed(metr, xi, chi), rl, anticommuting);
+ } else if (is_a<matrix>(metr)) {
+ matrix M = ex_to<matrix>(metr);
+ unsigned n = M.rows();
+ bool symmetric = true;
+ anticommuting = true;
+
+ static varidx xi((new symbol)->setflag(status_flags::dynallocated), n),
+ chi((new symbol)->setflag(status_flags::dynallocated), n);
+ if ((n == M.cols()) && (n == ex_to<varidx>(mu).get_dim())) {
+ for (unsigned i = 0; i < n; i++) {
+ for (unsigned j = i+1; j < n; j++) {
+ if (M(i, j) != M(j, i)) {
+ symmetric = false;
+ }
+ if (M(i, j) != -M(j, i)) {
+ anticommuting = false;
+ }
+ }
+ }
+ return clifford(unit, mu, indexed(metr, symmetric?symmetric2():not_symmetric(), xi, chi), rl, anticommuting);
+ } else {
+ throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be a square matrix with the same dimensions as index"));
+ }
+ } else {
+ throw(std::invalid_argument("clifford_unit(): metric for Clifford unit must be of type indexed, tensor or matrix"));
+ }