I need to create rule2
with the same right hand side of rule1
. This RHS contains If
statements (and in fact quite a few more things that are calculated with the matched symbols, before the final expression).
rule2 = LHS -> rule1[[2]]
ignores the If
statement, but works.
rule2 = LHS :> rule1[[2]]
does not work (does not associate matched stuff on the LHS)
I cannot use Condition (/;), because it clashes with another function that adds another Condition to the Rule
Minimal example:
rule1 = F[X_,n_?(#>=2&),a_,b_,ind__] :> If[a===b || Length[{ind}]===0, CANCEL, n*G[X,n,a,b,ind] ]
rule2 = H[X_,n_?(#>=0&),a_,b_,ind__] -> (rule1[[2]]/.n->n+2)
F[A,3,a,b,j]/.rule1 (*3 G[A, 3, a, b, j]*)
H[A,3,a,a,j]/.rule2 (*should CANCEL because a==b*)
Any help would be so useful.
ReplacePart
to replace part1
(the LHS) ofrule1
without affecting anything else $\endgroup$