Skip to main content
added 72 characters in body
Source Link
Lukas Lang
  • 34.6k
  • 1
  • 58
  • 99

Instead of "protecting" some kinds of expressions, you could just explicitly specify that you only want to replace products with integers:

Replace[ 4 x^2 (4 Subscript[a, 1] + Subscript[a, 2] - 7 Subscript[c, 4]), n_Integer a_ :> 2 n a, All ] 

This way, you don't risk forgetting to protect some form of expression

Instead of "protecting" some kinds of expressions, you could just explicitly specify that you only want to replace products with integers:

Replace[ 4 x^2 (4 Subscript[a, 1] + Subscript[a, 2] - 7 Subscript[c, 4]), n_Integer a_ :> 2 n a, All ] 

Instead of "protecting" some kinds of expressions, you could just explicitly specify that you only want to replace products with integers:

Replace[ 4 x^2 (4 Subscript[a, 1] + Subscript[a, 2] - 7 Subscript[c, 4]), n_Integer a_ :> 2 n a, All ] 

This way, you don't risk forgetting to protect some form of expression

Source Link
Lukas Lang
  • 34.6k
  • 1
  • 58
  • 99

Instead of "protecting" some kinds of expressions, you could just explicitly specify that you only want to replace products with integers:

Replace[ 4 x^2 (4 Subscript[a, 1] + Subscript[a, 2] - 7 Subscript[c, 4]), n_Integer a_ :> 2 n a, All ]