* Clifford now works with non-symmetric metric as well.
* Several small corrections and update of tutorial and automatic checks.
[V.Kisil]
#include "exams.h"
+const numeric half(1, 2);
+
static unsigned check_equal(const ex &e1, const ex &e2)
{
- ex e = e1 - e2;
+ ex e = normal(e1 - e2);
if (!e.is_zero()) {
- clog << e1 << "-" << e2 << " erroneously returned "
+ clog << "(" << e1 << ") - (" << e2 << ") erroneously returned "
<< e << " instead of 0" << endl;
return 1;
}
static unsigned check_equal_simplify(const ex &e1, const ex &e2)
{
- ex e = simplify_indexed(e1) - e2;
+ ex e = normal(simplify_indexed(e1) - e2);
if (!e.is_zero()) {
- clog << "simplify_indexed(" << e1 << ")-" << e2 << " erroneously returned "
- << e << " instead of 0" << endl;
+ clog << "simplify_indexed(" << e1 << ") - (" << e2 << ") erroneously returned "
+ << e << " instead of 0" << endl;
+ return 1;
+ }
+ return 0;
+}
+
+static unsigned check_equal_lst(const ex & e1, const ex & e2)
+{
+ for(int i = 0; i++; i < e1.nops()) {
+ ex e = e1.op(i) - e2.op(i);
+ if (!e.is_zero()) {
+ clog << "(" << e1 << ") - (" << e2 << ") erroneously returned "
+ << e << " instead of 0 (in the entry " << i << ")" << endl;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static unsigned check_equal_simplify_term(const ex & e1, const ex & e2, varidx & mu)
+{
+ ex e = expand_dummy_sum(normal(simplify_indexed(e1) - e2), true);
+
+ for (int j=0; j<4; j++) {
+ ex esub = e.subs(lst(mu == idx(j, mu.get_dim()), mu.toggle_variance() == idx(j, mu.get_dim())));
+ if (!(canonicalize_clifford(esub).is_zero())) {
+ clog << "simplify_indexed(" << e1 << ") - (" << e2 << ") erroneously returned "
+ << canonicalize_clifford(esub) << " instead of 0 for mu=" << j << endl;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static unsigned check_equal_simplify_term2(const ex & e1, const ex & e2)
+{
+ ex e = expand_dummy_sum(normal(simplify_indexed(e1) - e2), true);
+ if (!(canonicalize_clifford(e).is_zero())) {
+ clog << "simplify_indexed(" << e1 << ") - (" << e2 << ") erroneously returned "
+ << canonicalize_clifford(e) << " instead of 0" << endl;
return 1;
}
return 0;
}
+
static unsigned clifford_check1()
{
// checks general identities and contractions
return result;
}
+
static unsigned clifford_check6(const matrix & A)
{
varidx v(symbol("v"), 4), nu(symbol("nu"), 4), mu(symbol("mu"), 4),
psi(symbol("psi"),4), lam(symbol("lambda"), 4),
xi(symbol("xi"), 4), rho(symbol("rho"),4);
- ex G = A;
+ matrix A_symm(4,4), A2(4, 4);
+ A_symm = A.add(A.transpose()).mul(half);
+ A2 = A_symm.mul(A_symm);
- matrix A2(4, 4);
- A2 = A.mul(A);
ex e, e1;
-
+ bool anticommuting = ex_to<clifford>(clifford_unit(nu, A)).is_anticommuting();
int result = 0;
// checks general identities and contractions for clifford_unit
- e = dirac_ONE() * clifford_unit(mu, G) * dirac_ONE();
- result += check_equal(e, clifford_unit(mu, G));
+ e = dirac_ONE(2) * clifford_unit(mu, A, 2) * dirac_ONE(2);
+ result += check_equal(e, clifford_unit(mu, A, 2));
- e = clifford_unit(varidx(2, 4), G) * clifford_unit(varidx(1, 4), G)
- * clifford_unit(varidx(1, 4), G) * clifford_unit(varidx(2, 4), G);
+ e = clifford_unit(idx(2, 4), A) * clifford_unit(idx(1, 4), A)
+ * clifford_unit(idx(1, 4), A) * clifford_unit(idx(2, 4), A);
result += check_equal(e, A(1, 1) * A(2, 2) * dirac_ONE());
- e = clifford_unit(nu, G) * clifford_unit(nu.toggle_variance(), G);
+ e = clifford_unit(varidx(2, 4), A) * clifford_unit(varidx(1, 4), A)
+ * clifford_unit(varidx(1, 4), A) * clifford_unit(varidx(2, 4), A);
+ result += check_equal(e, A(1, 1) * A(2, 2) * dirac_ONE());
+
+ e = clifford_unit(nu, A) * clifford_unit(nu.toggle_variance(), A);
result += check_equal_simplify(e, A.trace() * dirac_ONE());
- e = clifford_unit(nu, G) * clifford_unit(nu, G);
- result += check_equal_simplify(e, indexed(G, sy_symm(), nu, nu) * dirac_ONE());
+ e = clifford_unit(nu, A) * clifford_unit(nu, A);
+ result += check_equal_simplify(e, indexed(A_symm, sy_symm(), nu, nu) * dirac_ONE());
- e = clifford_unit(nu, G) * clifford_unit(nu.toggle_variance(), G) * clifford_unit(mu, G);
- result += check_equal_simplify(e, A.trace() * clifford_unit(mu, G));
+ e = clifford_unit(nu, A) * clifford_unit(nu.toggle_variance(), A) * clifford_unit(mu, A);
+ result += check_equal_simplify(e, A.trace() * clifford_unit(mu, A));
- e = clifford_unit(nu, G) * clifford_unit(mu, G) * clifford_unit(nu.toggle_variance(), G);
- result += check_equal_simplify(e, 2*indexed(G, sy_symm(), mu, mu)*clifford_unit(mu, G) - A.trace()*clifford_unit(mu, G));
+ e = clifford_unit(nu, A) * clifford_unit(mu, A) * clifford_unit(nu.toggle_variance(), A);
+ if (anticommuting)
+ result += check_equal_simplify(e, 2*indexed(A_symm, sy_symm(), mu, mu)*clifford_unit(mu, A) - A.trace()*clifford_unit(mu, A));
+
+ result += check_equal_simplify_term(e, 2 * indexed(A_symm, sy_symm(), nu.toggle_variance(), mu) *clifford_unit(nu, A)-A.trace()*clifford_unit(mu, A), mu);
- e = clifford_unit(nu, G) * clifford_unit(nu.toggle_variance(), G)
- * clifford_unit(mu, G) * clifford_unit(mu.toggle_variance(), G);
+ e = clifford_unit(nu, A) * clifford_unit(nu.toggle_variance(), A)
+ * clifford_unit(mu, A) * clifford_unit(mu.toggle_variance(), A);
result += check_equal_simplify(e, pow(A.trace(), 2) * dirac_ONE());
- e = clifford_unit(mu, G) * clifford_unit(nu, G)
- * clifford_unit(nu.toggle_variance(), G) * clifford_unit(mu.toggle_variance(), G);
+ e = clifford_unit(mu, A) * clifford_unit(nu, A)
+ * clifford_unit(nu.toggle_variance(), A) * clifford_unit(mu.toggle_variance(), A);
result += check_equal_simplify(e, pow(A.trace(), 2) * dirac_ONE());
- e = clifford_unit(mu, G) * clifford_unit(nu, G)
- * clifford_unit(mu.toggle_variance(), G) * clifford_unit(nu.toggle_variance(), G);
- result += check_equal_simplify(e, 2*A2.trace()*dirac_ONE() - pow(A.trace(), 2)*dirac_ONE());
+ e = clifford_unit(mu, A) * clifford_unit(nu, A)
+ * clifford_unit(mu.toggle_variance(), A) * clifford_unit(nu.toggle_variance(), A);
+ if (anticommuting)
+ result += check_equal_simplify(e, 2*A2.trace()*dirac_ONE() - pow(A.trace(), 2)*dirac_ONE());
- e = clifford_unit(mu.toggle_variance(), G) * clifford_unit(nu, G)
- * clifford_unit(mu, G) * clifford_unit(nu.toggle_variance(), G);
- result += check_equal_simplify(e, 2*A2.trace()*dirac_ONE() - pow(A.trace(), 2)*dirac_ONE());
+ result += check_equal_simplify_term2(e, 2*indexed(A_symm, sy_symm(), nu.toggle_variance(), mu.toggle_variance()) * clifford_unit(mu, A) * clifford_unit(nu, A) - pow(A.trace(), 2)*dirac_ONE());
- e = clifford_unit(nu.toggle_variance(), G) * clifford_unit(rho.toggle_variance(), G)
- * clifford_unit(mu, G) * clifford_unit(rho, G) * clifford_unit(nu, G);
- e = e.simplify_indexed().collect(clifford_unit(mu, G));
- result += check_equal(e, (pow(A.trace(), 2)+4-4*A.trace()*indexed(A, mu, mu)) * clifford_unit(mu, G));
+ e = clifford_unit(mu.toggle_variance(), A) * clifford_unit(nu, A)
+ * clifford_unit(mu, A) * clifford_unit(nu.toggle_variance(), A);
+ if (anticommuting) {
+ result += check_equal_simplify(e, 2*A2.trace()*dirac_ONE() - pow(A.trace(), 2)*dirac_ONE());
+ e1 = remove_dirac_ONE(simplify_indexed(e));
+ result += check_equal(e1, 2*A2.trace() - pow(A.trace(), 2));
+ }
- e = clifford_unit(nu.toggle_variance(), G) * clifford_unit(rho, G)
- * clifford_unit(mu, G) * clifford_unit(rho.toggle_variance(), G) * clifford_unit(nu, G);
- e = e.simplify_indexed().collect(clifford_unit(mu, G));
- result += check_equal(e, (pow(A.trace(), 2)+4-4*A.trace()*indexed(A, mu, mu))* clifford_unit(mu, G));
+ result += check_equal_simplify_term2(e, 2*indexed(A_symm, nu, mu) * clifford_unit(mu.toggle_variance(), A) * clifford_unit(nu.toggle_variance(), A) - pow(A.trace(), 2)*dirac_ONE());
- // canonicalize_clifford() checks
- e = clifford_unit(mu, G) * clifford_unit(nu, G) + clifford_unit(nu, G) * clifford_unit(mu, G);
- result += check_equal(canonicalize_clifford(e), 2*dirac_ONE()*indexed(G, sy_symm(), mu, nu));
-
- e = (clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G)
- + clifford_unit(nu, G) * clifford_unit(lam, G) * clifford_unit(mu, G)
- + clifford_unit(lam, G) * clifford_unit(mu, G) * clifford_unit(nu, G)
- - clifford_unit(nu, G) * clifford_unit(mu, G) * clifford_unit(lam, G)
- - clifford_unit(lam, G) * clifford_unit(nu, G) * clifford_unit(mu, G)
- - clifford_unit(mu, G) * clifford_unit(lam, G) * clifford_unit(nu, G)) / 6
- + indexed(G, sy_symm(), mu, nu) * clifford_unit(lam, G)
- - indexed(G, sy_symm(), mu, lam) * clifford_unit(nu, G)
- + indexed(G, sy_symm(), nu, lam) * clifford_unit(mu, G)
- - clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G);
+ e = clifford_unit(nu.toggle_variance(), A) * clifford_unit(rho.toggle_variance(), A)
+ * clifford_unit(mu, A) * clifford_unit(rho, A) * clifford_unit(nu, A);
+ e = e.simplify_indexed().collect(clifford_unit(mu, A));
+ if (anticommuting)
+ result += check_equal(e, (4*indexed(A2, sy_symm(), mu, mu) - 4 * indexed(A_symm, sy_symm(), mu, mu)*A.trace() +pow(A.trace(), 2)) * clifford_unit(mu, A));
+
+ result += check_equal_simplify_term(e, 4* indexed(A_symm, sy_symm(), nu.toggle_variance(), rho)*indexed(A_symm, sy_symm(), rho.toggle_variance(), mu) *clifford_unit(nu, A)
+ - 2*A.trace() * (clifford_unit(rho, A) * indexed(A_symm, sy_symm(), rho.toggle_variance(), mu)
+ + clifford_unit(nu, A) * indexed(A_symm, sy_symm(), nu.toggle_variance(), mu)) + pow(A.trace(),2)* clifford_unit(mu, A), mu);
+
+ e = clifford_unit(nu.toggle_variance(), A) * clifford_unit(rho, A)
+ * clifford_unit(mu, A) * clifford_unit(rho.toggle_variance(), A) * clifford_unit(nu, A);
+ e = e.simplify_indexed().collect(clifford_unit(mu, A));
+ if (anticommuting)
+ result += check_equal(e, (4*indexed(A2, sy_symm(), mu, mu) - 4*indexed(A_symm, sy_symm(), mu, mu)*A.trace() +pow(A.trace(), 2))* clifford_unit(mu, A));
+
+ result += check_equal_simplify_term(e, 4* indexed(A_symm, sy_symm(), nu.toggle_variance(), rho)*indexed(A_symm, sy_symm(), rho.toggle_variance(), mu) *clifford_unit(nu, A)
+ - 2*A.trace() * (clifford_unit(rho, A) * indexed(A_symm, sy_symm(), rho.toggle_variance(), mu)
+ + clifford_unit(nu, A) * indexed(A_symm, sy_symm(), nu.toggle_variance(), mu)) + pow(A.trace(),2)* clifford_unit(mu, A), mu);
+
+ e = clifford_unit(mu, A) * clifford_unit(nu, A) + clifford_unit(nu, A) * clifford_unit(mu, A);
+ result += check_equal(canonicalize_clifford(e), 2*dirac_ONE()*indexed(A_symm, sy_symm(), mu, nu));
+
+ e = (clifford_unit(mu, A) * clifford_unit(nu, A) * clifford_unit(lam, A)
+ + clifford_unit(nu, A) * clifford_unit(lam, A) * clifford_unit(mu, A)
+ + clifford_unit(lam, A) * clifford_unit(mu, A) * clifford_unit(nu, A)
+ - clifford_unit(nu, A) * clifford_unit(mu, A) * clifford_unit(lam, A)
+ - clifford_unit(lam, A) * clifford_unit(nu, A) * clifford_unit(mu, A)
+ - clifford_unit(mu, A) * clifford_unit(lam, A) * clifford_unit(nu, A)) / 6
+ + indexed(A_symm, sy_symm(), mu, nu) * clifford_unit(lam, A)
+ - indexed(A_symm, sy_symm(), mu, lam) * clifford_unit(nu, A)
+ + indexed(A_symm, sy_symm(), nu, lam) * clifford_unit(mu, A)
+ - clifford_unit(mu, A) * clifford_unit(nu, A) * clifford_unit(lam, A);
result += check_equal(canonicalize_clifford(e), 0);
// lst_to_clifford() and clifford_inverse() check
- symbol x("x"), y("y"), t("t"), z("z");
+ realsymbol x("x"), y("y"), t("t"), z("z");
- ex c = clifford_unit(nu, G, 1);
- e = lst_to_clifford(lst(t, x, y, z), mu, G, 1) * lst_to_clifford(lst(1, 2, 3, 4), c);
+ ex c = clifford_unit(nu, A, 1);
+ e = lst_to_clifford(lst(t, x, y, z), mu, A, 1) * lst_to_clifford(lst(1, 2, 3, 4), c);
e1 = clifford_inverse(e);
- result += check_equal((e*e1).simplify_indexed().normal(), dirac_ONE(1));
+ result += check_equal_lst((e*e1).simplify_indexed(), dirac_ONE(1));
+
+ // Moebius map (both forms) checks for symmetric metrics only
+ matrix M1(2, 2), M2(2, 2);
+ c = clifford_unit(nu, A);
+
+ e = clifford_moebius_map(0, dirac_ONE(),
+ dirac_ONE(), 0, lst(t, x, y, z), A); // this is just the inversion
+ M1 = 0, dirac_ONE(),
+ dirac_ONE(), 0;
+ e1 = clifford_moebius_map(M1, lst(t, x, y, z), A); // the inversion again
+ result += check_equal_lst(e, e1);
+
+ e1 = clifford_to_lst(clifford_inverse(lst_to_clifford(lst(t, x, y, z), mu, A)), c);
+ result += check_equal_lst(e, e1);
+
+ e = clifford_moebius_map(dirac_ONE(), lst_to_clifford(lst(1, 2, 3, 4), nu, A),
+ 0, dirac_ONE(), lst(t, x, y, z), A); //this is just a shift
+ M2 = dirac_ONE(), lst_to_clifford(lst(1, 2, 3, 4), c),
+ 0, dirac_ONE();
+ e1 = clifford_moebius_map(M2, lst(t, x, y, z), c); // the same shift
+ result += check_equal_lst(e, e1);
+
+ result += check_equal(e, lst(t+1, x+2, y+3, z+4));
+
+ // Check the group law for Moebius maps
+ e = clifford_moebius_map(M1, ex_to<lst>(e1), c); //composition of M1 and M2
+ e1 = clifford_moebius_map(M1.mul(M2), lst(t, x, y, z), c); // the product M1*M2
+ result += check_equal_lst(e, e1);
return result;
}
-static unsigned clifford_check7()
+
+static unsigned clifford_check7(const ex & G, const symbol & dim)
{
// checks general identities and contractions
unsigned result = 0;
- symbol dim("D");
varidx mu(symbol("mu"), dim), nu(symbol("nu"), dim), rho(symbol("rho"), dim),
psi(symbol("psi"),dim), lam(symbol("lambda"), dim), xi(symbol("xi"), dim);
- ex e;
+ ex e, G_base;
- ex G = minkmetric();
+ if (is_a<indexed>(G))
+ G_base = G.op(0);
+ else
+ G_base = G;
e = dirac_ONE() * dirac_ONE();
result += check_equal(e, dirac_ONE());
e = e.simplify_indexed().collect(clifford_unit(mu, G));
result += check_equal(e, pow(2 - dim, 2).expand() * clifford_unit(mu, G));
- // canonicalize_clifford() checks
- e = clifford_unit(mu, G) * clifford_unit(nu, G) + clifford_unit(nu, G) * clifford_unit(mu, G);
- result += check_equal(canonicalize_clifford(e), 2*dirac_ONE()*indexed(G, sy_symm(), mu, nu));
-
- e = (clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G)
- + clifford_unit(nu, G) * clifford_unit(lam, G) * clifford_unit(mu, G)
- + clifford_unit(lam, G) * clifford_unit(mu, G) * clifford_unit(nu, G)
- - clifford_unit(nu, G) * clifford_unit(mu, G) * clifford_unit(lam, G)
- - clifford_unit(lam, G) * clifford_unit(nu, G) * clifford_unit(mu, G)
- - clifford_unit(mu, G) * clifford_unit(lam, G) * clifford_unit(nu, G)) / 6
- + indexed(G, sy_symm(), mu, nu) * clifford_unit(lam, G)
- - indexed(G, sy_symm(), mu, lam) * clifford_unit(nu, G)
- + indexed(G, sy_symm(), nu, lam) * clifford_unit(mu, G)
- - clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G);
- result += check_equal(canonicalize_clifford(e), 0);
-
+ // canonicalize_clifford() checks, only for symmetric metrics
+ if (ex_to<symmetry>(ex_to<indexed>(ex_to<clifford>(clifford_unit(mu, G)).get_metric()).get_symmetry()).has_symmetry()) {
+ e = clifford_unit(mu, G) * clifford_unit(nu, G) + clifford_unit(nu, G) * clifford_unit(mu, G);
+ result += check_equal(canonicalize_clifford(e), 2*dirac_ONE()*indexed(G_base, sy_symm(), nu, mu));
+
+ e = (clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G)
+ + clifford_unit(nu, G) * clifford_unit(lam, G) * clifford_unit(mu, G)
+ + clifford_unit(lam, G) * clifford_unit(mu, G) * clifford_unit(nu, G)
+ - clifford_unit(nu, G) * clifford_unit(mu, G) * clifford_unit(lam, G)
+ - clifford_unit(lam, G) * clifford_unit(nu, G) * clifford_unit(mu, G)
+ - clifford_unit(mu, G) * clifford_unit(lam, G) * clifford_unit(nu, G)) / 6
+ + indexed(G_base, sy_symm(), mu, nu) * clifford_unit(lam, G)
+ - indexed(G_base, sy_symm(), mu, lam) * clifford_unit(nu, G)
+ + indexed(G_base, sy_symm(), nu, lam) * clifford_unit(mu, G)
+ - clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G);
+ result += check_equal(canonicalize_clifford(e), 0);
+ } else {
+ e = clifford_unit(mu, G) * clifford_unit(nu, G) + clifford_unit(nu, G) * clifford_unit(mu, G);
+ result += check_equal(canonicalize_clifford(e), dirac_ONE()*(indexed(G_base, mu, nu) + indexed(G_base, nu, mu)));
+
+ e = (clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G)
+ + clifford_unit(nu, G) * clifford_unit(lam, G) * clifford_unit(mu, G)
+ + clifford_unit(lam, G) * clifford_unit(mu, G) * clifford_unit(nu, G)
+ - clifford_unit(nu, G) * clifford_unit(mu, G) * clifford_unit(lam, G)
+ - clifford_unit(lam, G) * clifford_unit(nu, G) * clifford_unit(mu, G)
+ - clifford_unit(mu, G) * clifford_unit(lam, G) * clifford_unit(nu, G)) / 6
+ + half * (indexed(G_base, mu, nu) + indexed(G_base, nu, mu)) * clifford_unit(lam, G)
+ - half * (indexed(G_base, mu, lam) + indexed(G_base, lam, mu)) * clifford_unit(nu, G)
+ + half * (indexed(G_base, nu, lam) + indexed(G_base, lam, nu)) * clifford_unit(mu, G)
+ - clifford_unit(mu, G) * clifford_unit(nu, G) * clifford_unit(lam, G);
+ result += check_equal(canonicalize_clifford(e), 0);
+ }
return result;
}
result += clifford_check4(); cout << '.' << flush;
result += clifford_check5(); cout << '.' << flush;
+ // anticommuting, symmetric examples
+ result += clifford_check6(ex_to<matrix>(diag_matrix(lst(-1, 1, 1, 1)))); cout << '.' << flush;
+ result += clifford_check6(ex_to<matrix>(diag_matrix(lst(-1, -1, -1, -1)))); cout << '.' << flush;
+ result += clifford_check6(ex_to<matrix>(diag_matrix(lst(-1, 1, 1, -1)))); cout << '.' << flush;
+ result += clifford_check6(ex_to<matrix>(diag_matrix(lst(-1, 0, 1, -1)))); cout << '.' << flush;
+ result += clifford_check6(ex_to<matrix>(diag_matrix(lst(-3, 0, 2, -1)))); cout << '.' << flush;
+
+ realsymbol s("s"), t("t"); // symbolic entries in matric
+ result += clifford_check6(ex_to<matrix>(diag_matrix(lst(-1, 1, s, t)))); cout << '.' << flush;
+
matrix A(4, 4);
- A = -1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0, 1;
+ A = 1, 0, 0, 0, // anticommuting, not symmetric, Tr=0
+ 0, -1, 0, 0,
+ 0, 0, 0, -1,
+ 0, 0, 1, 0;
result += clifford_check6(A); cout << '.' << flush;
- A = -1, 0, 0, 0,
- 0,-1, 0, 0,
- 0, 0,-1, 0,
- 0, 0, 0,-1;
+ A = 1, 0, 0, 0, // anticommuting, not symmetric, Tr=2
+ 0, 1, 0, 0,
+ 0, 0, 0, -1,
+ 0, 0, 1, 0;
result += clifford_check6(A); cout << '.' << flush;
-
- A = -1, 0, 0, 0,
- 0, 1, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0,-1;
+
+ A = 1, 0, 0, 0, // not anticommuting, symmetric, Tr=0
+ 0, -1, 0, 0,
+ 0, 0, 0, -1,
+ 0, 0, -1, 0;
result += clifford_check6(A); cout << '.' << flush;
- A = -1, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 1, 0,
- 0, 0, 0,-1;
+ A = 1, 0, 0, 0, // not anticommuting, symmetric, Tr=2
+ 0, 1, 0, 0,
+ 0, 0, 0, -1,
+ 0, 0, -1, 0;
result += clifford_check6(A); cout << '.' << flush;
- result += clifford_check7(); cout << '.' << flush;
+ A = 1, 1, 0, 0, // not anticommuting, not symmetric, Tr=4
+ 0, 1, 1, 0,
+ 0, 0, 1, 1,
+ 0, 0, 0, 1;
+ result += clifford_check6(A); cout << '.' << flush;
+
+ symbol dim("D");
+ result += clifford_check7(minkmetric(), dim); cout << '.' << flush;
+
+ varidx chi(symbol("chi"), dim), xi(symbol("xi"), dim);
+ result += clifford_check7(lorentz_g(xi, chi), dim); cout << '.' << flush;
if (!result) {
cout << " passed " << endl;
@}
@end example
+@cindex @code{expand_dummy_sum()}
+A dummy index summation like
+@tex
+$ a_i b^i$
+@end tex
+@ifnottex
+a.i b~i
+@end ifnottex
+can be expanded for indices with numeric
+dimensions (e.g. 3) into the explicit sum like
+@tex
+$a_1b^1+a_2b^2+a_3b^3 $.
+@end tex
+@ifnottex
+a.1 b~1 + a.2 b~2 + a.3 b~3.
+@end ifnottex
+This is performed by the function
+
+@example
+ ex expand_dummy_sum(const ex & e, bool subs_idx = false);
+@end example
+
+which takes an expression @code{e} and returns the expanded sum for all
+dummy indices with numeric dimensions. If the parameter @code{subs_idx}
+is set to @code{true} then all substitutions are made by @code{idx} class
+indices, i.e. without variance. In this case the above sum
+@tex
+$ a_i b^i$
+@end tex
+@ifnottex
+a.i b~i
+@end ifnottex
+will be expanded to
+@tex
+$a_1b_1+a_2b_2+a_3b_3 $.
+@end tex
+@ifnottex
+a.1 b.1 + a.2 b.2 + a.3 b.3.
+@end ifnottex
+
+
@cindex @code{simplify_indexed()}
@subsection Simplifying indexed expressions
@end tex
satisfying the identities
@tex
-$e_i e_j + e_j e_i = M(i, j) $
+$e_i e_j + e_j e_i = M(i, j) + M(j, i) $
@end tex
@ifnottex
-e~i e~j + e~j e~i = M(i, j)
+e~i e~j + e~j e~i = M(i, j) + M(j, i)
@end ifnottex
-for some matrix (@code{metric})
-@math{M(i, j)}, which may be non-symmetric and containing symbolic
-entries. Such generators are created by the function
+for some bilinear form (@code{metric})
+@math{M(i, j)}, which may be non-symmetric (see arXiv:math.QA/9911180)
+and contain symbolic entries. Such generators are created by the
+function
@example
- ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
+ ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0,
+ bool anticommuting = false);
@end example
where @code{mu} should be a @code{varidx} class object indexing the
-generators, @code{metr} defines the metric @math{M(i, j)} and can be
+generators, an index @code{mu} with a numeric value may be of type
+@code{idx} as well.
+Parameter @code{metr} defines the metric @math{M(i, j)} and can be
represented by a square @code{matrix}, @code{tensormetric} or @code{indexed} class
-object, optional parameter @code{rl} allows to distinguish different
-Clifford algebras (which will commute with each other). Note that the call
-@code{clifford_unit(mu, minkmetric())} creates something very close to
-@code{dirac_gamma(mu)}. The method @code{clifford::get_metric()} returns a
-metric defining this Clifford number.
+object. Optional parameter @code{rl} allows to distinguish different
+Clifford algebras, which will commute with each other. The last
+optional parameter @code{anticommuting} defines if the anticommuting
+assumption (i.e.
+@tex
+$e_i e_j + e_j e_i = 0$)
+@end tex
+@ifnottex
+e~i e~j + e~j e~i = 0)
+@end ifnottex
+will be used for contraction of Clifford units. If the @code{metric} is
+supplied by a @code{matrix} object, then the value of
+@code{anticommuting} is calculated automatically and the supplied one
+will be ignored. One can overcome this by giving @code{metric} through
+matrix wrapped into an @code{indexed} object.
+
+Note that the call @code{clifford_unit(mu, minkmetric())} creates
+something very close to @code{dirac_gamma(mu)}, although
+@code{dirac_gamma} have more efficient simplification mechanism.
+@cindex @code{clifford::get_metric()}
+The method @code{clifford::get_metric()} returns a metric defining this
+Clifford number.
+@cindex @code{clifford::is_anticommuting()}
+The method @code{clifford::is_anticommuting()} returns the
+@code{anticommuting} property of a unit.
If the matrix @math{M(i, j)} is in fact symmetric you may prefer to create
the Clifford algebra units with a call like that
ex e = clifford_unit(mu, indexed(M, sy_symm(), i, j));
@end example
-since this may yield some further automatic simplifications.
+since this may yield some further automatic simplifications. Again, for a
+metric defined through a @code{matrix} such a symmetry is detected
+automatically.
Individual generators of a Clifford algebra can be accessed in several
ways. For example
$e_0^2=1 $, $e_1^2=-1$, $e_2^2=0$ and $e_3^2=s$.
@end tex
@ifnottex
-@code{pow(e0, 2) = 1}, @code{pow(e1, 2) = -1}, @code{pow(e2, 2) = 0} and @code{pow(e3, 2) = s}.
+@code{pow(e0, 2) = 1}, @code{pow(e1, 2) = -1}, @code{pow(e2, 2) = 0} and
+@code{pow(e3, 2) = s}.
@end ifnottex
@cindex @code{lst_to_clifford()}
@example
ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr,
- unsigned char rl = 0);
+ unsigned char rl = 0, bool anticommuting = false);
ex lst_to_clifford(const ex & v, const ex & e);
@end example
with @samp{e.k}
directly supplied in the second form of the procedure. In the first form
the Clifford unit @samp{e.k} is generated by the call of
-@code{clifford_unit(mu, metr, rl)}. The previous code may be rewritten
+@code{clifford_unit(mu, metr, rl, anticommuting)}. The previous code may be rewritten
with the help of @code{lst_to_clifford()} as follows
@example
@ifnottex
@samp{(e c.k + c.k e)/pow(c.k, 2)}. If @samp{pow(c.k, 2)}
@end ifnottex
-is zero or is not a @code{numeric} for some @samp{k}
+is zero or is not @code{numeric} for some @samp{k}
then the method will be automatically changed to symbolic. The same effect
is obtained by the assignment (@code{algebraic = false}) in the procedure call.
The function @code{canonicalize_clifford()} works for a
generic Clifford algebra in a similar way as for Dirac gammas.
-The last provided function is
+The next provided function is
@cindex @code{clifford_moebius_map()}
@example
ex clifford_moebius_map(const ex & a, const ex & b, const ex & c,
const ex & d, const ex & v, const ex & G,
- unsigned char rl = 0);
+ unsigned char rl = 0, bool anticommuting = false);
ex clifford_moebius_map(const ex & M, const ex & v, const ex & G,
- unsigned char rl = 0);
+ unsigned char rl = 0, bool anticommuting = false);
@end example
It takes a list or vector @code{v} and makes the Moebius (conformal or
linear-fractional) transformation @samp{v -> (av+b)/(cv+d)} defined by
the matrix @samp{M = [[a, b], [c, d]]}. The parameter @code{G} defines
-the metric of the surrounding (pseudo-)Euclidean space. This can be a
-matrix or a Clifford unit, in the later case the parameter @code{rl} is
-ignored even if supplied. The returned value of this function is a list
-of components of the resulting vector.
-
-LaTeX output for Clifford units looks like @code{\clifford[1]@{e@}^@{@{\nu@}@}},
-where @code{1} is the @code{representation_label} and @code{\nu} is the
-index of the corresponding unit. This provides a flexible typesetting
-with a suitable defintion of the @code{\clifford} command. For example, the
-definition
+the metric of the surrounding (pseudo-)Euclidean space. This can be an
+indexed object, tensormetric, matrix or a Clifford unit, in the later
+case the optional parameters @code{rl} and @code{anticommuting} are ignored
+even if supplied. The returned value of this function is a list of
+components of the resulting vector.
+
+@cindex @code{clifford_max_label()}
+Finally the function
+
+@example
+char clifford_max_label(const ex & e, bool ignore_ONE = false);
+@end example
+
+can detect a presence of Clifford objects in the expression @code{e}: if
+such objects are found it returns the maximal
+@code{representation_label} of them, otherwise @code{-1}. The optional
+parameter @code{ignore_ONE} indicates if @code{dirac_ONE} objects should
+be ignored during the search.
+
+LaTeX output for Clifford units looks like
+@code{\clifford[1]@{e@}^@{@{\nu@}@}}, where @code{1} is the
+@code{representation_label} and @code{\nu} is the index of the
+corresponding unit. This provides a flexible typesetting with a suitable
+defintion of the @code{\clifford} command. For example, the definition
@example
\newcommand@{\clifford@}[1][]@{@}
@end example
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdexcept>
+
#include "clifford.h"
#include "ex.h"
return m;
}
-clifford::clifford() : representation_label(0), metric(default_metric())
+clifford::clifford() : representation_label(0), metric(default_metric()), anticommuting(false)
{
tinfo_key = TINFO_clifford;
}
/** Construct object without any indices. This constructor is for internal
* use only. Use the dirac_ONE() function instead.
* @see dirac_ONE */
-clifford::clifford(const ex & b, unsigned char rl) : inherited(b), representation_label(rl), metric(0)
+clifford::clifford(const ex & b, unsigned char rl, bool anticommut) : inherited(b), representation_label(rl), metric(0), anticommuting(anticommut)
{
tinfo_key = TINFO_clifford;
}
* use only. Use the clifford_unit() or dirac_gamma() functions instead.
* @see clifford_unit
* @see dirac_gamma */
-clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl) : inherited(b, mu), representation_label(rl), metric(metr)
+clifford::clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl, bool anticommut) : inherited(b, mu), representation_label(rl), metric(metr), anticommuting(anticommut)
{
GINAC_ASSERT(is_a<varidx>(mu));
tinfo_key = TINFO_clifford;
}
-clifford::clifford(unsigned char rl, const ex & metr, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl), metric(metr)
+clifford::clifford(unsigned char rl, const ex & metr, bool anticommut, const exvector & v, bool discardable) : inherited(not_symmetric(), v, discardable), representation_label(rl), metric(metr), anticommuting(anticommut)
{
tinfo_key = TINFO_clifford;
}
-clifford::clifford(unsigned char rl, const ex & metr, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr)
+clifford::clifford(unsigned char rl, const ex & metr, bool anticommut, std::auto_ptr<exvector> vp) : inherited(not_symmetric(), vp), representation_label(rl), metric(metr), anticommuting(anticommut)
{
tinfo_key = TINFO_clifford;
}
n.find_unsigned("label", rl);
representation_label = rl;
n.find_ex("metric", metric, sym_lst);
+ n.find_bool("anticommuting", anticommuting);
}
void clifford::archive(archive_node & n) const
inherited::archive(n);
n.add_unsigned("label", representation_label);
n.add_ex("metric", metric);
+ n.add_bool("anticommuting", anticommuting);
}
DEFAULT_UNARCHIVE(clifford)
// functions overriding virtual functions from base classes
//////////
-ex clifford::get_metric(const ex & i, const ex & j) const
+ex clifford::get_metric(const ex & i, const ex & j, bool symmetrised) const
{
- return indexed(metric, symmetric2(), i, j);
+ 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 indexed(metric.op(0), ex_to<symmetry>(ex_to<indexed>(metric).get_symmetry()), i, j);
+ }
+ } else {
+ // should not really happen since all constructors but clifford() make the metric an indexed object
+ return indexed(metric, i, j);
+ }
}
bool clifford::same_metric(const ex & other) const
{
if (is_a<clifford>(other)) {
- return get_metric().is_equal(ex_to<clifford>(other).get_metric());
+ return same_metric(ex_to<clifford>(other).get_metric());
} else if (is_a<indexed>(other)) {
return get_metric(other.op(1), other.op(2)).is_equal(other);
} else
* used in cliffordunit::contract_with(). */
static int find_same_metric(exvector & v, ex & c)
{
- for (int i=0; i<v.size();i++) {
- if (!is_a<clifford>(v[i]) && is_a<indexed>(v[i])
- && ex_to<clifford>(c).same_metric(v[i])
- && (ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[0]
- || ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[0])) {
- return ++i; // next to found
+ for (size_t i=0; i<v.size(); i++) {
+ if (is_a<indexed>(v[i]) && !is_a<clifford>(v[i])
+ && ((ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[0]
+ && ex_to<varidx>(c.op(1)) == ex_to<indexed>(v[i]).get_indices()[1])
+ || (ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[0]
+ && ex_to<varidx>(c.op(1)).toggle_variance() == ex_to<indexed>(v[i]).get_indices()[1]))) {
+ return i; // the index of the found
}
}
- return 0; //nothing found
+ return -1; //nothing found
}
/** Contraction of a Clifford unit with something else. */
return false;
// Find if a previous contraction produces the square of self
- int prev_square = find_same_metric(v, self[0]);
- varidx d((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim());
- ex squared_metric = unit.get_metric(self->op(1), d) * unit.get_metric(d.toggle_variance(), other->op(1));
+ int prev_square = find_same_metric(v, *self);
+ const varidx d((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim()),
+ in1((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim()),
+ in2((new symbol)->setflag(status_flags::dynallocated), ex_to<idx>(self->op(1)).get_dim());
+ ex squared_metric;
+ if (prev_square > -1)
+ squared_metric = simplify_indexed(indexed(v[prev_square].op(0), in1, d)
+ * unit.get_metric(d.toggle_variance(), in2, true)).op(0);
+
+ exvector::iterator before_other = other - 1;
+ const varidx & mu = ex_to<varidx>(self->op(1));
+ const varidx & mu_toggle = ex_to<varidx>(other->op(1));
+ const varidx & alpha = ex_to<varidx>(before_other->op(1));
// e~mu e.mu = Tr ONE
if (other - self == 1) {
- if (prev_square != 0) {
- *self = squared_metric;
- v[prev_square-1] = _ex1;
- } else
- *self = unit.get_metric(self->op(1), other->op(1));
+ if (prev_square > -1) {
+ *self = indexed(squared_metric, mu, mu_toggle);
+ v[prev_square] = _ex1;
+ } else {
+ *self = unit.get_metric(mu, mu_toggle, true);
+ }
*other = dirac_ONE(rl);
return true;
- // e~mu e~alpha e.mu = (2e~alpha^2-Tr) e~alpha
- } else if (other - self == 2
- && is_a<clifford>(self[1])) {
-
- const ex & ia = self[1].op(1);
- const ex & ib = self[1].op(1);
- if (is_a<tensmetric>(unit.get_metric()))
- *self = 2 - unit.get_metric(self->op(1), other->op(1));
- else if (prev_square != 0) {
- *self = 2-squared_metric;
- v[prev_square-1] = _ex1;
- } else
- *self = 2*unit.get_metric(ia, ib) - unit.get_metric(self->op(1), other->op(1));
- *other = _ex1;
- return true;
-
- // e~mu S e~alpha e.mu = 2 e~alpha^3 S - e~mu S e.mu e~alpha
+ } else if (other - self == 2) {
+ if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
+ if (ex_to<clifford>(*self).is_anticommuting()) {
+ // e~mu e~alpha e.mu = (2*pow(e~alpha, 2) -Tr(B)) e~alpha
+ if (prev_square > -1) {
+ *self = 2 * indexed(squared_metric, alpha, alpha)
+ - indexed(squared_metric, mu, mu_toggle);
+ v[prev_square] = _ex1;
+ } else {
+ *self = 2 * unit.get_metric(alpha, alpha, true) - unit.get_metric(mu, mu_toggle, true);
+ }
+ *other = _ex1;
+ return true;
+
+ } else {
+ // e~mu e~alpha e.mu = 2*e~mu B(alpha, mu.toggle_variance())-Tr(B) e~alpha
+ *self = 2 * (*self) * unit.get_metric(alpha, mu_toggle, true) - unit.get_metric(mu, mu_toggle, true) * (*before_other);
+ *before_other = _ex1;
+ *other = _ex1;
+ return true;
+ }
+ } else {
+ // e~mu S e.mu = Tr S ONE
+ *self = unit.get_metric(mu, mu_toggle, true);
+ *other = dirac_ONE(rl);
+ return true;
+ }
+ } else {
+ // e~mu S e~alpha e.mu = 2 e~mu S B(alpha, mu.toggle_variance()) - e~mu S e.mu e~alpha
// (commutate contracted indices towards each other, simplify_indexed()
// will re-expand and re-run the simplification)
- } else {
- exvector::iterator it = self + 1, next_to_last = other - 1;
- while (it != other) {
- if (!is_a<clifford>(*it))
- return false;
- ++it;
+ if (std::find_if(self + 1, other, is_not_a_clifford()) != other) {
+ return false;
}
-
- it = self + 1;
- ex S = _ex1;
- while (it != next_to_last) {
- S *= *it;
- *it++ = _ex1;
+
+ ex S = ncmul(exvector(self + 1, before_other), true);
+
+ if (is_a<clifford>(*before_other) && ex_to<clifford>(*before_other).get_representation_label() == rl) {
+ if (ex_to<clifford>(*self).is_anticommuting()) {
+ if (prev_square > -1) {
+ *self = 2 * (*before_other) * S * indexed(squared_metric, alpha, alpha)
+ - (*self) * S * (*other) * (*before_other);
+ } else {
+ *self = 2 * (*before_other) * S * unit.get_metric(alpha, alpha, true) - (*self) * S * (*other) * (*before_other);
+ }
+ } else {
+ *self = 2 * (*self) * S * unit.get_metric(alpha, mu_toggle, true) - (*self) * S * (*other) * (*before_other);
+ }
+ } else {
+ // simply commutes
+ *self = (*self) * S * (*other) * (*before_other);
}
-
- const ex & ia = next_to_last->op(1);
- const ex & ib = next_to_last->op(1);
- if (is_a<tensmetric>(unit.get_metric()))
- *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last);
- else if (prev_square != 0) {
- *self = 2 * (*next_to_last) * S - (*self) * S * (*other) * (*next_to_last)*unit.get_metric(self->op(1),self->op(1));
- v[prev_square-1] = _ex1;
- } else
- *self = 2 * (*next_to_last) * S* unit.get_metric(ia,ib) - (*self) * S * (*other) * (*next_to_last);
- *next_to_last = _ex1;
- *other = _ex1;
+
+ std::fill(self + 1, other + 1, _ex1);
return true;
}
-
- }
-
+ }
return false;
}
const ex & ia = a.op(1);
const ex & ib = b.op(1);
if (ia.is_equal(ib)) { // gamma~alpha gamma~alpha -> g~alpha~alpha
- a = ex_to<clifford>(a).get_metric(ia, ib);
+ a = ex_to<clifford>(a).get_metric(ia, ib, true);
b = dirac_ONE(representation_label);
something_changed = true;
}
}
if (s.empty())
- return clifford(diracone(), representation_label) * sign;
+ return dirac_ONE(representation_label) * sign;
if (something_changed)
return reeval_ncmul(s) * sign;
else
ex clifford::thiscontainer(const exvector & v) const
{
- return clifford(representation_label, get_metric(), v);
+ return clifford(representation_label, get_metric(), is_anticommuting(), v);
}
ex clifford::thiscontainer(std::auto_ptr<exvector> vp) const
{
- return clifford(representation_label, get_metric(), vp);
+ return clifford(representation_label, get_metric(), is_anticommuting(), vp);
}
ex diracgamma5::conjugate() const
ex dirac_ONE(unsigned char rl)
{
static ex ONE = (new diracone)->setflag(status_flags::dynallocated);
- return clifford(ONE, rl);
+ return clifford(ONE, rl, false);
}
-ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl)
+ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl, bool anticommuting)
{
static ex unit = (new cliffordunit)->setflag(status_flags::dynallocated);
- if (!is_a<varidx>(mu))
- throw(std::invalid_argument("index of Clifford unit must be of type varidx"));
+ if (!is_a<idx>(mu))
+ throw(std::invalid_argument("clifford_unit(): index of Clifford unit must be of type idx or varidx"));
- 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<tensmetric>(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, tensormetric or matrix"));
+ }
}
ex dirac_gamma(const ex & mu, unsigned char rl)
static ex gamma = (new diracgamma)->setflag(status_flags::dynallocated);
if (!is_a<varidx>(mu))
- throw(std::invalid_argument("index of Dirac gamma must be of type varidx"));
+ throw(std::invalid_argument("dirac_gamma(): index of Dirac gamma must be of type varidx"));
- return clifford(gamma, mu, default_metric(), rl);
+ 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(gamma, mu, indexed(default_metric(), symmetric2(), xi, chi), rl, true);
}
ex dirac_gamma5(unsigned char rl)
ex b1, i1, b2, i2;
base_and_index(it[0], b1, i1);
base_and_index(it[1], b2, i2);
- it[0] = (ex_to<clifford>(save0).get_metric(i1, i2) * b1 * b2).simplify_indexed();
+ it[0] = (ex_to<clifford>(save0).get_metric(i1, i2, true) * b1 * b2).simplify_indexed();
it[1] = v.size() == 2 ? _ex2 * dirac_ONE(ex_to<clifford>(it[1]).get_representation_label()) : _ex2;
ex sum = ncmul(v);
it[0] = save1;
return e;
}
-ex remove_dirac_ONE(const ex & e, unsigned char rl)
+ex remove_dirac_ONE(const ex & e, unsigned char rl, unsigned options)
{
- pointer_to_map_function_1arg<unsigned char> fcn(remove_dirac_ONE, rl);
- if (is_a<clifford>(e) && ex_to<clifford>(e).get_representation_label() >= rl) {
- if (is_a<diracone>(e.op(0)))
+ pointer_to_map_function_2args<unsigned char, unsigned> fcn(remove_dirac_ONE, rl, options | 1);
+ bool need_reevaluation = false;
+ ex e1 = e;
+ if (! (options & 1) ) { // is not a child
+ if (options & 2)
+ e1 = expand_dummy_sum(e, true);
+ e1 = canonicalize_clifford(e1);
+ }
+
+ if (is_a<clifford>(e1) && ex_to<clifford>(e1).get_representation_label() >= rl) {
+ if (is_a<diracone>(e1.op(0)))
return 1;
+ else
+ throw(std::invalid_argument("remove_dirac_ONE(): expression is a non-scalar Clifford number!"));
+ } else if (is_a<add>(e1) || is_a<ncmul>(e1) || is_a<mul>(e1)
+ || is_a<matrix>(e1) || is_a<lst>(e1)) {
+ if (options & 3) // is a child or was already expanded
+ return e1.map(fcn);
else
- throw(std::invalid_argument("Expression is a non-scalar Clifford number!"));
- } else if (is_a<add>(e) || is_a<ncmul>(e) || is_a<mul>(e) // || is_a<pseries>(e) || is_a<integral>(e)
- || is_a<matrix>(e) || is_a<lst>(e)) {
- return e.map(fcn);
- } else if (is_a<power>(e)) {
- return pow(remove_dirac_ONE(e.op(0)), e.op(1));
- } else
- return e;
+ try {
+ return e1.map(fcn);
+ } catch (std::exception &p) {
+ need_reevaluation = true;
+ }
+ } else if (is_a<power>(e1)) {
+ if (options & 3) // is a child or was already expanded
+ return pow(remove_dirac_ONE(e1.op(0), rl, options | 1), e1.op(1));
+ else
+ try {
+ return pow(remove_dirac_ONE(e1.op(0), rl, options | 1), e1.op(1));
+ } catch (std::exception &p) {
+ need_reevaluation = true;
+ }
+ }
+ if (need_reevaluation)
+ return remove_dirac_ONE(e, rl, options | 2);
+ return e1;
}
-ex clifford_norm(const ex & e)
+char clifford_max_label(const ex & e, bool ignore_ONE)
{
- return sqrt(remove_dirac_ONE(canonicalize_clifford(e * clifford_bar(e)).simplify_indexed()));
+ if (is_a<clifford>(e))
+ if (ignore_ONE && is_a<diracone>(e.op(0)))
+ return -1;
+ else
+ return ex_to<clifford>(e).get_representation_label();
+ else {
+ char rl = -1;
+ for (size_t i=0; i < e.nops(); i++)
+ rl = (rl > clifford_max_label(e.op(i), ignore_ONE)) ? rl : clifford_max_label(e.op(i), ignore_ONE);
+ return rl;
+ }
}
+ex clifford_norm(const ex & e)
+{
+ return sqrt(remove_dirac_ONE(e * clifford_bar(e)));
+}
+
ex clifford_inverse(const ex & e)
{
ex norm = clifford_norm(e);
if (!norm.is_zero())
return clifford_bar(e) / pow(norm, 2);
else
- throw(std::invalid_argument("Cannot find inverse of Clifford number with zero norm!"));
+ throw(std::invalid_argument("clifford_inverse(): cannot find inverse of Clifford number with zero norm!"));
}
-ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl)
+ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl, bool anticommuting)
{
if (!ex_to<idx>(mu).is_dim_numeric())
- throw(std::invalid_argument("Index should have a numeric dimension"));
- ex e = clifford_unit(mu, metr, rl);
+ throw(std::invalid_argument("lst_to_clifford(): Index should have a numeric dimension"));
+ ex e = clifford_unit(mu, metr, rl, anticommuting);
return lst_to_clifford(v, e);
}
if (dim == max)
return indexed(v, ex_to<varidx>(mu).toggle_variance()) * e;
else
- throw(std::invalid_argument("Dimensions of vector and clifford unit mismatch"));
+ throw(std::invalid_argument("lst_to_clifford(): dimensions of vector and clifford unit mismatch"));
} else
- throw(std::invalid_argument("First argument should be a vector vector"));
+ throw(std::invalid_argument("lst_to_clifford(): first argument should be a vector vector"));
} else if (is_a<lst>(v)) {
if (dim == ex_to<lst>(v).nops())
return indexed(matrix(dim, 1, ex_to<lst>(v)), ex_to<varidx>(mu).toggle_variance()) * e;
else
- throw(std::invalid_argument("List length and dimension of clifford unit mismatch"));
+ throw(std::invalid_argument("lst_to_clifford(): list length and dimension of clifford unit mismatch"));
} else
- throw(std::invalid_argument("Cannot construct from anything but list or vector"));
+ throw(std::invalid_argument("lst_to_clifford(): cannot construct from anything but list or vector"));
} else
- throw(std::invalid_argument("The second argument should be a Clifford unit"));
+ throw(std::invalid_argument("lst_to_clifford(): the second argument should be a Clifford unit"));
}
-
+
/** Auxiliary structure to define a function for striping one Clifford unit
* from vectors. Used in clifford_to_lst(). */
static ex get_clifford_comp(const ex & e, const ex & c)
if (ind > e.nops())
ind = j;
else
- throw(std::invalid_argument("Expression is a Clifford multi-vector"));
+ throw(std::invalid_argument("get_clifford_comp(): expression is a Clifford multi-vector"));
if (ind < e.nops()) {
ex S = 1;
bool same_value_index, found_dummy;
}
return (found_dummy ? S : 0);
} else
- throw(std::invalid_argument("Expression is not a Clifford vector to the given units"));
+ throw(std::invalid_argument("get_clifford_comp(): expression is not a Clifford vector to the given units"));
} else if (e.is_zero())
return e;
else if (is_a<clifford>(e) && ex_to<clifford>(e).same_metric(c))
else
return 1;
else
- throw(std::invalid_argument("Expression is not usable as a Clifford vector"));
+ throw(std::invalid_argument("get_clifford_comp(): expression is not usable as a Clifford vector"));
}
GINAC_ASSERT(is_a<clifford>(c));
varidx mu = ex_to<varidx>(c.op(1));
if (! mu.is_dim_numeric())
- throw(std::invalid_argument("Index should have a numeric dimension"));
+ throw(std::invalid_argument("clifford_to_lst(): index should have a numeric dimension"));
unsigned int D = ex_to<numeric>(mu.get_dim()).to_int();
if (algebraic) // check if algebraic method is applicable
or (not is_a<numeric>(pow(c.subs(mu == i), 2))))
algebraic = false;
lst V;
- if (algebraic)
+ if (algebraic) {
for (unsigned int i = 0; i < D; i++)
V.append(remove_dirac_ONE(
simplify_indexed(canonicalize_clifford(e * c.subs(mu == i) + c.subs(mu == i) * e))
/ (2*pow(c.subs(mu == i), 2))));
- else {
+ } else {
ex e1 = canonicalize_clifford(e);
- for (unsigned int i = 0; i < D; i++)
- V.append(get_clifford_comp(e1, c.subs(c.op(1) == i)));
+ try {
+ for (unsigned int i = 0; i < D; i++)
+ V.append(get_clifford_comp(e1, c.subs(c.op(1) == i)));
+ } catch (std::exception &p) {
+ /* Try to expand dummy summations to simplify the expression*/
+ e1 = canonicalize_clifford(expand_dummy_sum(e1, true));
+ for (unsigned int i = 0; i < D; i++)
+ V.append(get_clifford_comp(e1, c.subs(c.op(1) == i)));
+ }
}
return V;
}
-ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl)
+ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl, bool anticommuting)
{
ex x, D, cu;
if (! is_a<matrix>(v) && ! is_a<lst>(v))
- throw(std::invalid_argument("parameter v should be either vector or list"));
+ throw(std::invalid_argument("clifford_moebius_map(): parameter v should be either vector or list"));
if (is_a<clifford>(G)) {
cu = G;
D = ex_to<varidx>(G.op(1)).get_dim();
else if (is_a<matrix>(G))
D = ex_to<matrix>(G).rows();
- else throw(std::invalid_argument("metric should be an indexed object, matrix, or a Clifford unit"));
+ else throw(std::invalid_argument("clifford_moebius_map(): metric should be an indexed object, matrix, or a Clifford unit"));
varidx mu((new symbol)->setflag(status_flags::dynallocated), D);
- cu = clifford_unit(mu, G, rl);
+ cu = clifford_unit(mu, G, rl, anticommuting);
}
-
+
x = lst_to_clifford(v, cu);
ex e = simplify_indexed(canonicalize_clifford((a * x + b) * clifford_inverse(c * x + d)));
return clifford_to_lst(e, cu, false);
}
-ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl)
+ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl, bool anticommuting)
{
if (is_a<matrix>(M))
- return clifford_moebius_map(ex_to<matrix>(M)(0,0), ex_to<matrix>(M)(0,1),
- ex_to<matrix>(M)(1,0), ex_to<matrix>(M)(1,1), v, G, rl);
+ return clifford_moebius_map(ex_to<matrix>(M)(0,0), ex_to<matrix>(M)(0,1),
+ ex_to<matrix>(M)(1,0), ex_to<matrix>(M)(1,1), v, G, rl, anticommuting);
else
- throw(std::invalid_argument("parameter M should be a matrix"));
+ throw(std::invalid_argument("clifford_moebius_map(): parameter M should be a matrix"));
}
} // namespace GiNaC
// other constructors
public:
- clifford(const ex & b, unsigned char rl = 0);
- clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl = 0);
+ clifford(const ex & b, unsigned char rl = 0, bool anticommut = false);
+ clifford(const ex & b, const ex & mu, const ex & metr, unsigned char rl = 0, bool anticommut = false);
// internal constructors
- clifford(unsigned char rl, const ex & metr, const exvector & v, bool discardable = false);
- clifford(unsigned char rl, const ex & metr, std::auto_ptr<exvector> vp);
+ clifford(unsigned char rl, const ex & metr, bool anticommut, const exvector & v, bool discardable = false);
+ clifford(unsigned char rl, const ex & metr, bool anticommut, std::auto_ptr<exvector> vp);
// functions overriding virtual functions from base classes
public:
public:
unsigned char get_representation_label() const { return representation_label; }
ex get_metric() const { return metric; }
- ex get_metric(const ex & i, const ex & j) const;
+ ex get_metric(const ex & i, const ex & j, bool symmetrised = false) const;
bool same_metric(const ex & other) const;
+ bool is_anticommuting() const { return anticommuting; } //**< See the member variable anticommuting */
protected:
void do_print_dflt(const print_dflt & c, unsigned level) const;
// member variables
private:
unsigned char representation_label; /**< Representation label to distinguish independent spin lines */
- ex metric;
+ ex metric; /**< Metric of the space, all constructors make it an indexed object */
+ bool anticommuting; /**< Simplifications for anticommuting units is much simpler and we need this info readily available */
};
/** Create a Clifford unit object.
*
* @param mu Index (must be of class varidx or a derived class)
- * @param metr Metric (should be of class tensmetric or a derived class, or a matrix)
+ * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
* @param rl Representation label
* @return newly constructed Clifford unit object */
-ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0);
+ex clifford_unit(const ex & mu, const ex & metr, unsigned char rl = 0, bool anticommuting = false);
/** Create a Dirac gamma object.
*
/** Replaces dirac_ONE's (with a representation_label no less than rl) in e with 1.
* For the default value rl = 0 remove all of them. Aborts if e contains any
* clifford_unit with representation_label to be removed.
- *
+ *
+ * @param e Expression to be processed
+ * @param rl Value of representation label
+ * @param options Defines some internal use */
+ex remove_dirac_ONE(const ex & e, unsigned char rl = 0, unsigned options = 0);
+
+/** Returns the maximal representation label of a clifford object
+ * if e contains at least one, otherwise returns -1
+ *
* @param e Expression to be processed
- * @param rl Value of representation label */
-ex remove_dirac_ONE(const ex & e, unsigned char rl = 0);
+ * @ignore_ONE defines if clifford_ONE should be ignored in the search*/
+char clifford_max_label(const ex & e, bool ignore_ONE = false);
/** Calculation of the norm in the Clifford algebra. */
ex clifford_norm(const ex & e);
*
* @param v List or vector of coordinates
* @param mu Index (must be of class varidx or a derived class)
- * @param metr Metric (should be of class tensmetric or a derived class, or a matrix)
+ * @param metr Metric (should be indexed, tensmetric or a derived class, or a matrix)
* @param rl Representation label
* @param e Clifford unit object
* @return Clifford vector with given components */
-ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl = 0);
+ex lst_to_clifford(const ex & v, const ex & mu, const ex & metr, unsigned char rl = 0, bool anticommuting = false);
ex lst_to_clifford(const ex & v, const ex & e);
/** An inverse function to lst_to_clifford(). For given Clifford vector extracts
* @param v Vector to be transformed
* @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
* @param rl Representation label
+ * @param anticommuting indicates if Clifford units anticommutes
* @return List of components of the transformed vector*/
-ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl = 0);
+ex clifford_moebius_map(const ex & a, const ex & b, const ex & c, const ex & d, const ex & v, const ex & G, unsigned char rl = 0, bool anticommuting = false);
/** The second form of Moebius transformations defined by a 2x2 Clifford matrix M
* This function takes the transformation matrix M as a single entity.
* @param v Vector to be transformed
* @param G Metric of the surrounding space, may be a Clifford unit then the next parameter is ignored
* @param rl Representation label
+ * @param anticommuting indicates if Clifford units anticommutes
* @return List of components of the transformed vector*/
-ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0);
+ex clifford_moebius_map(const ex & M, const ex & v, const ex & G, unsigned char rl = 0, bool anticommuting = false);
} // namespace GiNaC