Message Boards Message Boards

0
|
538 Views
|
4 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Does With[] do anything Assuming[] doesn't do?

Posted 1 month ago

What's the relationship between With[] and Assuming[]? From my reading of documentation, Assuming[] is a generalized (possibly newer) version of With[]. Do they react to Assumptions-> the same?

POSTED BY: Jay Gourley
4 Replies
Posted 1 month ago

Thanks, Michael Rogers. The examples were especially helpful. Your observation that Simplify thinks 5 is simpler than 15 let me to discover ComplexityFunction[], a neat option. Too bad Simplify[] doesn't work on the documentation.

POSTED BY: Jay Gourley

With is a localization construct, similar to Block in a number of ways. It specifies specific values for localized parameters.

Assuming restricts parameters to restricted: e.g. Reals, Regions, etc... And various functions, e.g., Integrate, FullSimplify, ... algorithmically behave in particular ways depending on the assumptions specified.

They are different beasts entierly.

POSTED BY: David Reiss

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.

POSTED BY: Michael Rogers
Posted 1 month ago

I'm not sure what you mean by "they react", but I emphatically disagree with the notion that Assuming is a generalized version of With.

With suspends evaluation of its body until after the specified replacements are made. It performs a mutation on the expression in complete ignorance of what the expression might "mean". On the other hand Assuming applies logical constraints that affect the evaluation of some expression, in particular expressions meant to "solve" for something.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract