Ordering and pattern matching

View: New views
4 Messages — Rating Filter:   Alert me  

Ordering and pattern matching

by Chris Kelly-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

_______________________________________________
GiNaC-list mailing list
GiNaC-list@...
https://www.cebix.net/mailman/listinfo/ginac-list

Re: Ordering and pattern matching

by Vladimir V. Kisil-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

                Hi, Chris,

>>>>> On Tue, 25 Aug 2009 16:12:37 +0100, Chris Kelly <giltirn@...> said:

    CK> grips with the clifford algebra classes. I am trying to perform
    CK> the simple substitution:
    CK> A_mu gamma_mu B_nu gamma_nu = A_mu A_nu delta_mu,nu (Euclidean space).

        Why you are doing this replacement? I do not think it is mathematically
  correct, it shall be:

A_mu gamma_mu B_nu gamma_nu + B_nu gamma_nu A_mu gamma_mu  = A_mu A_nu delta_mu,nu  

  You can get that answer by canonicalize_clifford() method without any
  substitution.

    CK> Here is some example code:

    CK>   ex metric = unit_matrix(4); idx i(symbol("i"),4) ,
    CK>   j(symbol("j"),4); ex al_i = clifford_unit(i,metric); //Use
    CK>   //  generalised clifford gamma  matrices for euclidean space
    CK>   //Create generic 'slashed' symbols with euclidean metric

        You may prefer to use delta tensor rather than unit matrices to
  create this Clifford units---output of simplification will be more
  transparent.

  Best wishes,
  Vladimir
--
Vladimir V. Kisil     email: kisilv@...
--                      www: http://maths.leeds.ac.uk/~kisilv/
_______________________________________________
GiNaC-list mailing list
GiNaC-list@...
https://www.cebix.net/mailman/listinfo/ginac-list

Re: Ordering and pattern matching

by Chris Kelly-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Vladimir,

On Tue, Sep 1, 2009 at 12:15 PM, Vladimir V. Kisil <kisilv@...> wrote:

>>>>> On Tue, 25 Aug 2009 16:12:37 +0100, Chris Kelly <giltirn@...> said:

   CK> grips with the clifford algebra classes. I am trying to perform
   CK> the simple substitution:
   CK> A_mu gamma_mu B_nu gamma_nu = A_mu A_nu delta_mu,nu (Euclidean space).

       Why you are doing this replacement? I do not think it is mathematically
 correct, it shall be:

A_mu gamma_mu B_nu gamma_nu + B_nu gamma_nu A_mu gamma_mu  = A_mu A_nu delta_mu,nu

 You can get that answer by canonicalize_clifford() method without any
 substitution.

 
Indeed you are correct, it is only true when A=B. I over-generalised my example without thinking it through. In my main problem I only ever need to replace A_mu gamma_mu A_nu gamma_nu = A_mu A_nu delta_mu,nu. However my example still retains some validity in the sense that this replacement will not work either!
 
   CK> Here is some example code:

   CK>   ex metric = unit_matrix(4); idx i(symbol("i"),4) ,
   CK>   j(symbol("j"),4); ex al_i = clifford_unit(i,metric); //Use
   CK>   //  generalised clifford gamma  matrices for euclidean space
   CK>   //Create generic 'slashed' symbols with euclidean metric

       You may prefer to use delta tensor rather than unit matrices to
 create this Clifford units---output of simplification will be more
 transparent.

Thank you, i'll give this a try.

I don't suppose you have an answer to my question about whether there is 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?

Best,
Chris

_______________________________________________
GiNaC-list mailing list
GiNaC-list@...
https://www.cebix.net/mailman/listinfo/ginac-list

Re: Ordering and pattern matching

by Vladimir V. Kisil-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

                Hi, Chris,

>>>>> On Tue, 1 Sep 2009 18:33:31 +0100, Chris Kelly <giltirn@...> said:
    CK> I don't suppose you have an answer to my question about whether
    CK> there is some way to canonically order an expression by a set of
    CK> rules rather than by the hash value such that i can find a
    CK> pattern that is guaranteed to match?

        No. I just try to point out that you can do most of reasonable
  manipulations with Clifford algebras without canonical ordering and
  substitutions.

  Best wishes,
  Vladimir
--
Vladimir V. Kisil     email: kisilv@...
--                      www: http://maths.leeds.ac.uk/~kisilv/
_______________________________________________
GiNaC-list mailing list
GiNaC-list@...
https://www.cebix.net/mailman/listinfo/ginac-list