0
$\begingroup$

question might have an answer in this post (Efficient Search for specific Terms in symbolic Expression) but i don't understand how to convert it to my specific case

Through some definite integrals I am generating error functions like Erfc[g[4]] and Erfc[g[4]/Sqrt[2]] in the following expression

-(1/2) (g[1] - g[2]) (g[1] - g[3]) (g[2] - g[3]) (E^(-(1/2) g[4]^2) Sqrt[2 \[Pi]] Erfc[g[4]/Sqrt[2]] - 2 E^-g[4]^2 g[4] + Sqrt[\[Pi]] Erfc[g[4]] (-1 + 2 g[4]^2))

I would like to know I can retrieve the terms containing the Error functions (and preferably also the argument of them) so that I can target them specifically for further processing. Preferably I would like to generate a list {{X1,Y1},{X2,Y2},...} where X is the coefficient and Y is the argument of the error function.

$\endgroup$
0

1 Answer 1

3
$\begingroup$
Clear["Global`*"]

expr = -(1/2) (g[1] - g[2]) (g[1] - g[3]) (g[2] - 
     g[3]) (E^(-(1/2) g[4]^2) Sqrt[2 π] Erfc[g[4]/Sqrt[2]] - 
     2 E^-g[4]^2 g[4] + Sqrt[π] Erfc[g[4]] (-1 + 2 g[4]^2));

Collect terms with Erfc

expr2 = Collect[expr, Cases[expr, _Erfc, Infinity]]

(* -E^(-(1/2) g[4]^2) Sqrt[π/2]
   Erfc[g[4]/Sqrt[2]] (g[1] - g[2]) (g[1] - g[3]) (g[2] - g[3]) + 
 E^-g[4]^2 (g[1] - g[2]) (g[1] - g[3]) (g[2] - g[3]) g[4] - 
 1/2 Sqrt[π]
   Erfc[g[4]] (g[1] - g[2]) (g[1] - g[3]) (g[2] - g[3]) (-1 + 2 g[4]^2) *)

Verifying that the expressions are equivalent

expr == expr2 // Simplify

(* True *)

The result is

list = Cases[Collect[expr, Cases[expr, _Erfc, Infinity]], 
 x_. * Erfc[y_] :> {x, y}, 1]

(* {{-E^(-(1/2) g[4]^2) Sqrt[π/
   2] (g[1] - g[2]) (g[1] - g[3]) (g[2] - g[3]), g[4]/Sqrt[
  2]}, {-(1/2)
     Sqrt[π] (g[1] - g[2]) (g[1] - g[3]) (g[2] - g[3]) (-1 + 
     2 g[4]^2), g[4]}} *)
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.