Skip to main content
added 2 characters in body
Source Link
JuanC97
  • 632
  • 4
  • 12

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

Also, I know the number of maximum required replacement rules in advance.


Implementing {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, my pseudocode reads off

Xn = X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}]
Xn =-> Xn
Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}] -> Xn

which, translated into actual Mathematica code, gives me:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]

However,

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that the rule definition is not working properly, allegedly, because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character but I don't really get it. how could I fix this?

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

Also, I know the number of maximum required replacement rules in advance.


Implementing {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, my pseudocode reads off

Xn = X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}]
Xn = Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}]

which, translated into actual Mathematica code, gives me:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]

However,

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that the rule definition is not working properly, allegedly, because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character but I don't really get it.

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

Also, I know the number of maximum required replacement rules in advance.


Implementing {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, my pseudocode reads

X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}] -> Xn
Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}] -> Xn

which translated into actual Mathematica code gives:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]

However,

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that the rule definition is not working properly, allegedly because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character but I don't really get it. how could I fix this?

deleted 44 characters in body
Source Link
JuanC97
  • 632
  • 4
  • 12

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

andAlso, I know the number of maximum required replacement rules in advance.


I think it's better to implementImplementing {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, this way, themy pseudocode reads off

Xn = X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}]
Xn = Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}]

which, translated into actual Mathematica code, gives me:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]
 

However, running

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that thisthe rule definition is not working properly, seeminglyallegedly, because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character but I don't really get it. Could someone please clarify how to fix this then?

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

and I know the number of maximum required replacement rules in advance.


I think it's better to implement {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, this way, the pseudocode reads off

Xn = X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}]
Xn = Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}]

which, translated into actual Mathematica code gives:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]

However, running

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that this definition is not working properly, seemingly, because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character. Could someone please clarify how to fix this then?

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

Also, I know the number of maximum required replacement rules in advance.


Implementing {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, my pseudocode reads off

Xn = X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}]
Xn = Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}]

which, translated into actual Mathematica code, gives me:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]
 

However,

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that the rule definition is not working properly, allegedly, because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character but I don't really get it.

Source Link
JuanC97
  • 632
  • 4
  • 12

How to deal with procedurally generated rules and patterns?

I'm trying to procedurally generate replacement rules of the following form

X[{a,a}] -> X1
X[{a,b}]X[{b,a}] -> X2
X[{a,b}]X[{b,c}]X[{c,a}] -> X3
X[{a,b}]X[{b,c}]X[{c,d}]X[{d,a}] -> X4

and I know the number of maximum required replacement rules in advance.


I think it's better to implement {a1___, a2___, a3___, ... } instead of {a,b,c, ... }, this way, the pseudocode reads off

Xn = X[{a[1],a[2]}] X[{a[2],a[3]}]... X[{a[n-1],a[n]}] X[{a[n],a[1]}]
Xn = Product[ X[{a[i],a[i+1]}], {i,1,n-1} ] X[{a[n],a[1]}]

which, translated into actual Mathematica code gives:

MyRule[n_] := 
  a___ Product[ 
    Subscript[X, {Symbol["μ"<>ToString[i]<>"___"], Symbol["μ"<>ToString[i+1]<>"___"]}], 
  {i,1,n-1}] Subscript[X, 
      {Symbol["μ"<>ToString[n]<>"___"], Symbol["μ"<>ToString[1]<>"__"]}
  ] :> a Subscript[X, n]

However, running

Subscript[X, {a, b}] Subscript[X, {b, a}] /. MyRule[2]

shows that this definition is not working properly, seemingly, because of a conflict in the way the dummy indices are written and some issues with their 'Symbol' character. Could someone please clarify how to fix this then?