Mathematica provides Alternatives
, to match one of several patterns. In a rule, this is used as p1|p2|p3:>replacement
. I would like to have the opposite logic: p1&p2&p3:>replacement
(obviously using another notation) should match if all of p1
, p2
, and p3
match, and replacement
should be allowed to involve variables in all of p1
, p2
, p3
.
If one is simply concerned in whether all patterns match, one can use Except[Except[p1] | Except[p2] | Except[p3]]
, as described in Opposite of Alternatives or Logical AND of multiple patterns. I would like to do the same with rules, but the doubel-Except
construction will not populate named patterns (at least in v10.0 I get an Except::named
message).
Cases[{2/3, 1 + Pi, 3 - Gamma[I], 1 + x},
AndRuleDelayed[Plus[a_, b_], c_?NumericQ, {a, b, c}]]
(* should give
{{1, Pi, 1 + Pi}, {3, -Gamma[I], 3 - Gamma[I]}}
*)