Skip to main content
2 of 3
added 148 characters in body
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

You want to use Set rather than SetDelayed

Clear[f]

f[x_, y_] := x + 3 y /. {x -> -x y}

DownValues[f]

(*  {HoldPattern[f[x_, y_]] :> (x + 3 y /. {x -> -x y})}  *)

Trace will show you the evaluation sequence

f[1, 2] // Trace

enter image description here

Clear[f]

f[x_, y_] = x + 3 y /. {x -> -x y}

(*  3 y - x y  *)

DownValues[f]

(*  {HoldPattern[f[x_, y_]] :> 3 y - x y}  *)

f[1, 2] // Trace

enter image description here

Beware that if x or y are defined before the Set this will fail. For a solution see:

Bob Hanlon
  • 162.7k
  • 7
  • 81
  • 205