Dear all, I am new to GiNaC and am currently trying to get to grips with the clifford algebra classes. I am trying to perform the simple substitution: A_mu gamma_mu B_nu gamma_nu = A_mu A_nu delta_mu,nu (Euclidean space). The problem i am having is that the pattern match is not consistent over repeated use of the executable: sometimes the pattern will match, at other times it will not. It looks to me that this is related to the ordering of the expressions. Here is some example code: ----------------------------------------------------------------------------------------------------------------------------------- #include<iostream> #include<vector> #include<sstream> #include<ginac/ginac.h> using namespace std; using namespace GiNaC; //Aim is to identify A_mu gamma_mu B_nu gamma_nu == A_mu B_nu delta_mu,nu int main(){ ex metric = unit_matrix(4); idx i(symbol("i"),4) , j(symbol("j"),4); ex al_i = clifford_unit(i,metric); //Use generalised clifford gamma matrices for euclidean space ex al_j = clifford_unit(j,metric); //Create generic 'slashed' symbols with euclidean metric ex s1 = indexed(symbol("A"),i)*al_i; ex s2 = indexed(symbol("B"),j)*al_j; //Form the product ex prod = s1*s2; cout << s1*s2 << endl; //Attempt to match to patterns idx w1(wild(1),4), w2(wild(2),4); indexed in2_w1 = indexed(wild(2),w1); indexed in3_w2 = indexed(wild(3),w2); ex al_w1 = clifford_unit(w1,metric); ex al_w2 = clifford_unit(w2,metric); ex spat2_w1 = in2_w1*al_w1; ex spat3_w2 = in3_w2*al_w2; ex mpat = spat2_w1 * spat3_w2; cout << "MATCHING TO PATTERN: " << mpat << endl; cout << prod.match(mpat) << endl; ex mpat2 = in2_w1 * in3_w2 * al_w1 * al_w2; cout << "MATCHING TO PATTERN: " << mpat2 << endl; cout << prod.match(mpat2) << endl; ex mpat3 = in3_w2 * in2_w1 * al_w1 * al_w2; cout << "MATCHING TO PATTERN: " << mpat3 << endl; cout << prod.match(mpat3) << endl; return 0; } ----------------------------------------------------------- The output of this example is as follows: B.j*(e.i*e.j)*A.i <----- matching this against pattern MATCHING TO PATTERN: (e.($1)*e.($2))*$3.($2)*$2.($1) 0 MATCHING TO PATTERN: (e.($1)*e.($2))*$3.($2)*$2.($1) 0 MATCHING TO PATTERN: (e.($1)*e.($2))*$3.($2)*$2.($1) 0 So the expressions seem to all be reordered consistently, but in a different ordering to the object to which we wish to match. If i then add more code, reproducing the above code for the first pattern but using different wildcard indices: ----------------------------------------------------------- //Create new indices, perhaps hash ordering will be correct for these? idx w4(wild(4),4), w5(wild(5),4); indexed in2_w4 = indexed(wild(2),w4); indexed in3_w5 = indexed(wild(3),w5); ex al_w4 = clifford_unit(w4,metric); ex al_w5 = clifford_unit(w5,metric); ex spat2_w4 = in2_w4*al_w4; ex spat3_w5 = in3_w5*al_w5; ex mpat4 = spat2_w4 * spat3_w5; cout << "MATCHING TO PATTERN: " << mpat4 << endl; cout << prod.match(mpat4) << endl; ---------------------------------------------------------- The output sometimes (but not always) matches: First run: (object to match output as B.j*(e.i*e.j)*A.i ) MATCHING TO PATTERN: $2.($4)*(e.($4)*e.($5))*$3.($5) 0 Second run: (object to match output as (e.i*e.j)*B.j*A.i ) MATCHING TO PATTERN: (e.($4)*e.($5))*$3.($5)*$2.($4) 1 Third run: (object to match output as B.j*(e.i*e.j)*A.i ) <---- notice this is the same as the first run MATCHING TO PATTERN: (e.($4)*e.($5))*$3.($5)*$2.($4) 1 So for some reason the pattern matching is ordering dependent in a way that cannot be controlled. Strangely even if the pattern matches for a given run, the substitution code ------------------------------------------------- //Pattern sometimes matches, try a substitution for identity ex ident = in2_w4 * in3_w5 * delta_tensor(w4,w5); cout << "SUBSTITUTION RESULT:" << prod.subs(mpat4==ident) << endl; cout << "SUBSTITUTION RESULT (ALGEBRAIC):" << prod.subs(mpat4==ident,subs_options::algebraic) << endl; -------------------------------------------------- always seems to fail (or is ignored?) Second run: (object to match output as (e.i*e.j)*B.j*A.i ) SUBSTITUTION RESULT:(e.i*e.j)*B.j*A.i SUBSTITUTION RESULT (ALGEBRAIC):(e.i*e.j)*B.j*A.i Third run: (object to match output as B.j*(e.i*e.j)*A.i ) SUBSTITUTION RESULT:B.j*(e.i*e.j)*A.i SUBSTITUTION RESULT (ALGEBRAIC):B.j*(e.i*e.j)*A.i Does anyone know how to solve these issues? Thanks, Chris K
Hi Chris, On Tue, Aug 25, 2009 at 03:02:04PM +0100, Chris Kelly wrote:
I am new to GiNaC and am currently trying to get to grips with the clifford algebra classes. I am trying to perform the simple substitution: A_mu gamma_mu B_nu gamma_nu = A_mu A_nu delta_mu,nu (Euclidean space).
The problem i am having is that the pattern match is not consistent over repeated use of the executable: sometimes the pattern will match, at other times it will not.
The pattern matching operates on internal representation (in other words the matching is `syntactic', not algebraic). It tries to be smart(er) and handles sums and _commutative_ products in a special way (to account commutativity and associativity), but these tricks are not applicable to non-commutative products and/or tensors (a.k.a. indexed). Fortunately you don't need pattern matching to solve your problem. Simply choose appropriate basis (for 4-dimensional space with Minkowski metric that would be the set {1, gamma_mu, i/2 [ gamma_mu, gamma_nu ], gamma_5, gamma_5 gamma_mu }), and operate on (commutative) coefficients.
#include<iostream> #include<vector> #include<sstream> #include<ginac/ginac.h> using namespace std; using namespace GiNaC;
//Aim is to identify A_mu gamma_mu B_nu gamma_nu == A_mu B_nu delta_mu,nu int main(){
ex metric = unit_matrix(4); idx i(symbol("i"),4) , j(symbol("j"),4); // Use generalised clifford gamma matrices for euclidean space ex al_i = clifford_unit(i,metric); ex al_j = clifford_unit(j,metric);
//Create generic 'slashed' symbols with euclidean metric
ex s1 = indexed(symbol("A"),i)*al_i; ex s2 = indexed(symbol("B"),j)*al_j;
//Form the product ex prod = s1*s2;
cout << s1*s2 << endl;
//Attempt to match to patterns idx w1(wild(1),4), w2(wild(2),4); indexed in2_w1 = indexed(wild(2),w1);
Perhaps you mean wild(4) (not wild(2)) here.
indexed in3_w2 = indexed(wild(3),w2); ex al_w1 = clifford_unit(w1,metric); ex al_w2 = clifford_unit(w2,metric);
ex spat2_w1 = in2_w1*al_w1; ex spat3_w2 = in3_w2*al_w2;
ex mpat = spat2_w1 * spat3_w2; cout << "MATCHING TO PATTERN: " << mpat << endl; cout << prod.match(mpat) << endl;
ex mpat2 = in2_w1 * in3_w2 * al_w1 * al_w2;
Shuffling terms like this doesn't make any sense: GiNaC will put them into canonical order anyway. So either all mpat* will match prod, or none of them will match. [skipped]
Strangely even if the pattern matches for a given run, the substitution code
------------------------------------------------- //Pattern sometimes matches, try a substitution for identity
ex ident = in2_w4 * in3_w5 * delta_tensor(w4,w5);
cout << "SUBSTITUTION RESULT:" << prod.subs(mpat4==ident) << endl; cout << "SUBSTITUTION RESULT (ALGEBRAIC):" <<
Algebraic matching can not handle non-commutative products, so it won't be any different from syntactic one.
prod.subs(mpat4==ident,subs_options::algebraic) << endl; -------------------------------------------------- always seems to fail (or is ignored?)
This looks like a bug. I'll try to find out what's going on. Best regards, Alexei
Hi Alexei, Thank you for your reply. On Wed, Aug 26, 2009 at 7:01 AM, Alexei Sheplyakov <varg@metalica.kh.ua>wrote:
The pattern matching operates on internal representation (in other words the matching is `syntactic', not algebraic). It tries to be smart(er) and handles sums and _commutative_ products in a special way (to account commutativity and associativity), but these tricks are not applicable to non-commutative products and/or tensors (a.k.a. indexed). Fortunately you don't need pattern matching to solve your problem. Simply choose appropriate basis (for 4-dimensional space with Minkowski metric that would be the set {1, gamma_mu, i/2 [ gamma_mu, a gamma_nu ], gamma_5, gamma_5 gamma_mu }), and operate on (commutative) coefficients.
The larger problem i am trying to solve is to find the solution to a set of simultaneous equations involving gamma matrices and objects that can be represented by sums over products of gamma matrices. This is to be solved in Euclidean space rather than the canonical Minkowski space. The equations have the form S_i = a*Y + b*Y*PR*S_j + c*Y*PL*S_k where i,j,k are indices, lower-case objects are commuting coefficients and capitalised objects are non-commuting objects that can be represented by sums over products of gamma matrices as you say. I am solving for the 'S' objects, and PR,PL and Y are known, as are the commuting coefficients. A general way of representing an object on 16 element basis of dirac matrix products and the unit matrix would be as a 16 component vector. These must be defined as non-commuting object such that the correct ordering is retained and I would also need to write code defining the product of these objects. In all it looks like I would be better off sticking to the existing clifford algebra for this more complicated problem, although it would certainly simplify the simpler problem that I posed in the previous email.
#include<iostream> #include<vector> #include<sstream> #include<ginac/ginac.h> using namespace std; using namespace GiNaC;
//Aim is to identify A_mu gamma_mu B_nu gamma_nu == A_mu B_nu delta_mu,nu int main(){
ex metric = unit_matrix(4); idx i(symbol("i"),4) , j(symbol("j"),4); // Use generalised clifford gamma matrices for euclidean space ex al_i = clifford_unit(i,metric); ex al_j = clifford_unit(j,metric);
//Create generic 'slashed' symbols with euclidean metric
ex s1 = indexed(symbol("A"),i)*al_i; ex s2 = indexed(symbol("B"),j)*al_j;
//Form the product ex prod = s1*s2;
cout << s1*s2 << endl;
//Attempt to match to patterns idx w1(wild(1),4), w2(wild(2),4); indexed in2_w1 = indexed(wild(2),w1);
Perhaps you mean wild(4) (not wild(2)) here.
Indeed. Upon correcting this bug I find that the first set of patterns (which as you say are all ordered to the same form) now sometimes match the input. Unfortunately there are still instances in running when neither pattern matches the input. Is there some way to canonically order an expression by a set of rules rather than by the hash value such that i can find a pattern that is guaranteed to match? Thanks, Chris
participants (2)
-
Alexei Sheplyakov
-
Chris Kelly