159 views

Skip to first unread message

Oct 22, 2009, 2:18:46 PM10/22/09

to xAct Tensor Computer Algebra

When I use a rule to replace some parts, it does not replace all

suitable to be replaced, I don't why, could some can give a solution?

my intention is if one index of the two PD is the same as the index of

A, it should be replace by ruAz. I don't know if the rule is right, or

how to express such an idea with a rule?

~~~~~~~~~~~~~~~~~~~

<< xAct/xTensor.m;

DefManifold[M4, 4, IndexRange[a, t]]

DefMetric[-1, mg[-a, -b], PD, SymbolOfCovD -> {",", "\[PartialD]"},

FlatMetric -> True, PrintAs -> "\[Eta]"]

SortCovDsStart[PD];

PrintAs[EinsteinCD] ^:= "G"

PrintAs[RicciCD] ^:= "R"

PrintAs[RicciScalarCD] ^:= "R"

PrintAs[RiemannCD] ^:= "R"

PrintAs[ChristoffelCD] ^:= "\[CapitalGamma]"

$PrePrint = ScreenDollarIndices;

SetOptions[ToCanonical, UseMetricOnVBundle -> None];

DefTensor[A[a], M4];

ruAz = MakeRule[{PD[-b][PD[-a][A[a]]] , mg[-b, -e] mg[a, c] PD[-c][PD[-

a][A[e]]]}];

(* t1 will be replaced *)

t1 = PD[-a][PD[-b][A[a]]]

t1 /. ruAz

(*question: t2 will not be replaced*)

t2 = PD[-a][PD[-b][A[b]]]

t2 /. ruAz

~~~~~~~~~~~~~~~~~~~

suitable to be replaced, I don't why, could some can give a solution?

my intention is if one index of the two PD is the same as the index of

A, it should be replace by ruAz. I don't know if the rule is right, or

how to express such an idea with a rule?

~~~~~~~~~~~~~~~~~~~

<< xAct/xTensor.m;

DefManifold[M4, 4, IndexRange[a, t]]

DefMetric[-1, mg[-a, -b], PD, SymbolOfCovD -> {",", "\[PartialD]"},

FlatMetric -> True, PrintAs -> "\[Eta]"]

SortCovDsStart[PD];

PrintAs[EinsteinCD] ^:= "G"

PrintAs[RicciCD] ^:= "R"

PrintAs[RicciScalarCD] ^:= "R"

PrintAs[RiemannCD] ^:= "R"

PrintAs[ChristoffelCD] ^:= "\[CapitalGamma]"

$PrePrint = ScreenDollarIndices;

SetOptions[ToCanonical, UseMetricOnVBundle -> None];

DefTensor[A[a], M4];

ruAz = MakeRule[{PD[-b][PD[-a][A[a]]] , mg[-b, -e] mg[a, c] PD[-c][PD[-

a][A[e]]]}];

(* t1 will be replaced *)

t1 = PD[-a][PD[-b][A[a]]]

t1 /. ruAz

(*question: t2 will not be replaced*)

t2 = PD[-a][PD[-b][A[b]]]

t2 /. ruAz

~~~~~~~~~~~~~~~~~~~

Oct 25, 2009, 12:40:31 AM10/25/09

to xAct Tensor Computer Algebra

Hi Jiger,

> my intention is if one index of the two PD is the same as the index of

> A, it should be replace by ruAz. I don't know if the rule is right, or

> how to express such an idea with a rule?

> SortCovDsStart[PD];

> ruAz = MakeRule[{PD[-b][PD[-a][A[a]]] , mg[-b, -e] mg[a, c] PD[-c][PD[-a][A[e]]]}];

This rule is syntactically correct and given that you have used

SortCovDsStart[PD] I see that you expect xTensor to infer that the PDs

can be reordered in the pattern matching. But MakeRule is not that

intelligent. MakeRule is a way to construct the simplest rules, which

are also the most frequent, but if you need something with more

complicated pattern constructs, then you have to construct the rule

yourself. Using the output of MakeRule is a good starting point:

HoldPattern[PD[-(b_Symbol)][PD[-(a_Symbol)][A[a_Symbol]]]] :>

Module[{t$1, t$2, t$3}, mg[-b, -t$3]*mg[t$1, t$2]*PD[-t$2][PD[-t

$1][A[t$3]]]]

The problem is that the left hand side is only valid for what it says:

the derivative index matching the derivative of A is the most internal

one. We can simply add the two needed alternatives:

HoldPattern[PD[-(b_Symbol)][PD[-(a_Symbol)][A[a_Symbol]]] | PD[-

(a_Symbol)][PD[-(b_Symbol)][A[a_Symbol]]]] :>

Module[{t$1, t$2, t$3}, mg[-b, -t$3]*mg[t$1, t$2]*PD[-t$2][PD[-t

$1][A[t$3]]]]

Now this rule works in the two cases you need. You could also replace

the rule by a list of two rules, having the two needed left-hand-

sides, and the same right-hand-side.

I think that MakeRule should be able to see this equivalent case. I'll

add it in the future.

Cheers,

Jose.

> my intention is if one index of the two PD is the same as the index of

> A, it should be replace by ruAz. I don't know if the rule is right, or

> how to express such an idea with a rule?

> ruAz = MakeRule[{PD[-b][PD[-a][A[a]]] , mg[-b, -e] mg[a, c] PD[-c][PD[-a][A[e]]]}];

SortCovDsStart[PD] I see that you expect xTensor to infer that the PDs

can be reordered in the pattern matching. But MakeRule is not that

intelligent. MakeRule is a way to construct the simplest rules, which

are also the most frequent, but if you need something with more

complicated pattern constructs, then you have to construct the rule

yourself. Using the output of MakeRule is a good starting point:

HoldPattern[PD[-(b_Symbol)][PD[-(a_Symbol)][A[a_Symbol]]]] :>

Module[{t$1, t$2, t$3}, mg[-b, -t$3]*mg[t$1, t$2]*PD[-t$2][PD[-t

$1][A[t$3]]]]

The problem is that the left hand side is only valid for what it says:

the derivative index matching the derivative of A is the most internal

one. We can simply add the two needed alternatives:

HoldPattern[PD[-(b_Symbol)][PD[-(a_Symbol)][A[a_Symbol]]] | PD[-

(a_Symbol)][PD[-(b_Symbol)][A[a_Symbol]]]] :>

Module[{t$1, t$2, t$3}, mg[-b, -t$3]*mg[t$1, t$2]*PD[-t$2][PD[-t

$1][A[t$3]]]]

Now this rule works in the two cases you need. You could also replace

the rule by a list of two rules, having the two needed left-hand-

sides, and the same right-hand-side.

I think that MakeRule should be able to see this equivalent case. I'll

add it in the future.

Cheers,

Jose.

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu