Because of "Thou shalt not copypaste", I'd like to change my pair of replacements


(it's MUCH longer, so it actually saves :-) to something like this:


Alas, If doesn't work that way...
Bonus points if the Abs condition holds in a whole larger block because then I can reuse it for more F[] replacement rules. (I tried With, but that didn't work as expected either.)

  • 1
    $\begingroup$ Look up Condition. $\endgroup$ – Lukas Lang Jun 9 '18 at 19:40
  • $\begingroup$ As @Mathe172 mentioned, Condition is a quick way out: F[foo_, bar_] /; Abs[foo - bar] == 1 := replacement. I don't understand your bonus question though. Perhaps a less-minimal example is needed? $\endgroup$ – MarcoB Jun 9 '18 at 20:19
  • $\begingroup$ I too think that you can solve your problem by carefully reading about Condition and I also don't understand your bonus-question. I'm going to close this as a duplicate to the post Marco mentioned. If you still have problems after reading the documentation, please feel free to edit your question and make clear what you try to achieve and why it doesn't work. $\endgroup$ – halirutan Jun 10 '18 at 1:03
  • $\begingroup$ Ah, THX, Condition didn't show up on the first suggestions list. (Since I can apply it only to one F[] statement at a time, no bonus though :-) Of course I can apply it everywhere I need it, so no harm except to my natural lazyness :-) $\endgroup$ – Hauke Reddmann Jun 10 '18 at 11:53