- throw(std::invalid_argument("Index should have a numeric dimension"));
- unsigned dim = (ex_to<numeric>(ex_to<idx>(mu).get_dim())).to_int();
- ex c = clifford_unit(mu, metr, rl);
-
- if (is_a<matrix>(v)) {
- if (ex_to<matrix>(v).cols() > ex_to<matrix>(v).rows()) {
- min = ex_to<matrix>(v).rows();
- max = ex_to<matrix>(v).cols();
- } else {
- min = ex_to<matrix>(v).cols();
- max = ex_to<matrix>(v).rows();
- }
- if (min == 1) {
- if (dim == max)
- if (is_a<varidx>(mu)) // need to swap variance
- return indexed(v, ex_to<varidx>(mu).toggle_variance()) * c;
- else
- return indexed(v, mu) * c;
+ throw(std::invalid_argument("lst_to_clifford(): Index should have a numeric dimension"));
+ ex e = clifford_unit(mu, metr, rl);
+ return lst_to_clifford(v, e);
+}
+
+ex lst_to_clifford(const ex & v, const ex & e) {
+ unsigned min, max;
+
+ if (is_a<clifford>(e)) {
+ ex mu = e.op(1);
+ ex mu_toggle
+ = is_a<varidx>(mu) ? ex_to<varidx>(mu).toggle_variance() : mu;
+ unsigned dim = get_dim_uint(mu);
+
+ if (is_a<matrix>(v)) {
+ if (ex_to<matrix>(v).cols() > ex_to<matrix>(v).rows()) {
+ min = ex_to<matrix>(v).rows();
+ max = ex_to<matrix>(v).cols();
+ } else {
+ min = ex_to<matrix>(v).cols();
+ max = ex_to<matrix>(v).rows();
+ }
+ if (min == 1) {
+ if (dim == max)
+ return indexed(v, mu_toggle) * e;
+ else if (max - dim == 1) {
+ if (ex_to<matrix>(v).cols() > ex_to<matrix>(v).rows())
+ return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(ex_to<matrix>(v), 0, 1, 1, dim), mu_toggle) * e;
+ else
+ return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(ex_to<matrix>(v), 1, dim, 0, 1), mu_toggle) * e;
+ } else
+ throw(std::invalid_argument("lst_to_clifford(): dimensions of vector and clifford unit mismatch"));
+ } else
+ throw(std::invalid_argument("lst_to_clifford(): first argument should be a vector (nx1 or 1xn matrix)"));
+ } else if (v.info(info_flags::list)) {
+ if (dim == ex_to<lst>(v).nops())
+ return indexed(matrix(dim, 1, ex_to<lst>(v)), mu_toggle) * e;
+ else if (ex_to<lst>(v).nops() - dim == 1)
+ return v.op(0) * dirac_ONE(ex_to<clifford>(e).get_representation_label()) + indexed(sub_matrix(matrix(dim+1, 1, ex_to<lst>(v)), 1, dim, 0, 1), mu_toggle) * e;