Some differences:
Clear[x, y];
f[] := x;
Assuming[x == 5 && y == 15,
{x, y, Simplify[f[]], Simplify[x], Simplify[y], Simplify[y^2]}]
(* {x, y, 5, 5, y, 225} *)
With[{x = 5, y = 15},
{x, y, Simplify[f[]], Hold[x], Hold[y], Hold[y^2]}]
(* {5, 15, x, Hold[5], Hold[15], Hold[15^2]} *)
The only real effect of Assuming[P, expr]
is to change $Assumptions
temporarily to $Assumptions = And[P, $Assumptions]
. This might or might not affect the computation of expr
, since very few commands use $Assumptions
. Simplify[]
is one of the few. But since it does not consider 15
to be "simpler" than y
, it leaves y
unchanged. But 5
is simpler than x
and 225
is simpler than y^2
. Maybe someday they will have a ChatSimplify[]
so that your personal AI can advise Simplify[]
on what you consider simpler. If you are ever looking for a function that tries to apply assumptions without worrying about "simpler," I'd suggest Refine[]
.
With[]
replaces all the literal occurrences of x
and y
in the code following the list. Note that the code f[]
does not contain a literal occurrence of x
. When it is evaluated and becomes x
, With[]
has finished with its job and the value of f[]
is not replaced by 5
.
Maybe you were thinking the syntax of assuming is Assuming[{x = 5, y = 15}, expr]
? The equals should be double equals. While you may give a list of conditions as the first argument, Assuming[]
converts the List[]
to an And[]
when it combines the conditions with $Assumptions
.