Substitution rule for sums of similar objects?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
Consider objects like
obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])
I would like to have a substitution rule myRule
that would perform the following replacement
obj /. myRule
for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?
function-construction pattern-matching replacement
add a comment |Â
up vote
3
down vote
favorite
Consider objects like
obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])
I would like to have a substitution rule myRule
that would perform the following replacement
obj /. myRule
for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?
function-construction pattern-matching replacement
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Consider objects like
obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])
I would like to have a substitution rule myRule
that would perform the following replacement
obj /. myRule
for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?
function-construction pattern-matching replacement
Consider objects like
obj= (Sum[Subscript[A, i], i, 1, 5] Sum[Subscript[A, i], i, 3, 6] Sum[Subscript[A, i], i, 2, 3])/(
Sum[Subscript[A, i], i, 3, 8] Sum[Subscript[A, i], i, 1, 2] Sum[Subscript[A, i], i, 4, 6])
I would like to have a substitution rule myRule
that would perform the following replacement
obj /. myRule
for sequences of sums of $A_i$ of any lengths, and with indices not necessarily consecutive and not necessarily integer. How can this be done?
function-construction pattern-matching replacement
function-construction pattern-matching replacement
edited 2 hours ago


xzczd
24.9k466235
24.9k466235
asked 3 hours ago
Kagaratsch
4,42431246
4,42431246
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
Try the following:
obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
It can be even shorter:
obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
add a comment |Â
up vote
1
down vote
Here's an alternative that will work with subscripted A
s that have more than one subscript, which may (or may not) be what you want:
obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]
add a comment |Â
up vote
0
down vote
Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
Alternatively,
obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Try the following:
obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
It can be even shorter:
obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
add a comment |Â
up vote
3
down vote
accepted
Try the following:
obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
It can be even shorter:
obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Try the following:
obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
It can be even shorter:
obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
Try the following:
obj /. HoldPattern@Plus@a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
It can be even shorter:
obj /. HoldPattern@+a : (h : Subscript)[A, _] .. :> h[A, ## & @@ Last /@ a]
edited 2 hours ago
answered 3 hours ago


xzczd
24.9k466235
24.9k466235
add a comment |Â
add a comment |Â
up vote
1
down vote
Here's an alternative that will work with subscripted A
s that have more than one subscript, which may (or may not) be what you want:
obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]
add a comment |Â
up vote
1
down vote
Here's an alternative that will work with subscripted A
s that have more than one subscript, which may (or may not) be what you want:
obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Here's an alternative that will work with subscripted A
s that have more than one subscript, which may (or may not) be what you want:
obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]
Here's an alternative that will work with subscripted A
s that have more than one subscript, which may (or may not) be what you want:
obj /. HoldPattern[Plus[seq : Subscript[A, __] ..]] :>
Subscript[A, Sequence @@ Cases[seq, Subscript[A, inds__] :> inds]]
answered 57 mins ago


Pillsy
12.5k13179
12.5k13179
add a comment |Â
add a comment |Â
up vote
0
down vote
Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
Alternatively,
obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
add a comment |Â
up vote
0
down vote
Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
Alternatively,
obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
Alternatively,
obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
Block[Plus = (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &), obj] // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
Alternatively,
obj /. Plus -> (Subscript[#[[1]], ## & @@ ##[[All, -1]]] &) // TeXForm
$largefracA_2,3 A_3,4,5,6 A_1,2,3,4,5A_1,2 A_4,5,6 A_3,4,5,6,7,8$
answered 13 mins ago
kglr
167k8188390
167k8188390
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f184396%2fsubstitution-rule-for-sums-of-similar-objects%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password