15
$\begingroup$

Something changed with Solve between versions 12.1 and 12.2.

12.1:

Solve[n == n E^(r (1 - n)), n]
(* Solve::ifun -- Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. *)
(* {{n -> 0}, {n -> 1}} *)

$Assumptions = {n >= 0};
Solve[n == n E^(r (1 - n)), n]
(* Solve::ifun -- Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. *)
(* {{n -> 0}, {n -> 1}} *)

12.2:

Solve[n == n E^(r (1 - n)), n]
(* Solve::ifun -- Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. *)
(* {{n -> 0}, {n -> 1}} *)

$Assumptions = {n >= 0};
Solve[n == n E^(r (1 - n)), n]

enter image description here

Is this an improvement or a bug? It seems hard for the condition ConditionalExpression[1, Re[r] == 0 || Re[r] > 0 || Re[r] < 0] not to hold, but maybe I'm overlooking something.

Two work-arounds:

$Assumptions = {n >= 0, r \[Element] Reals};
Solve[n == n E^(r (1 - n)), n]

Solve[n == n E^(r (1 - n)), n, Reals]

both give {{n -> 0}, {n -> 1}} (no Solve::ifun either).

Another example, not fixable by including Reals:

$Assumptions = {n1 >= 0, n2 >= 0};
Solve[0 == n1 (1 - n1 - 0.5 n2), n1]

enter image description here

To be precise, my version is

$Version
(* 12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020) *)

Update: So, I think I'll just use Assumptions->{} to avoid these conditionals for now (while keeping $Assumptions set for use in Simplify).

$\endgroup$
7
  • 4
    $\begingroup$ Here’s a link to the recent updates page: "Solve (updated) — now takes Assumptions options". So there must be many chances under the hood. $\endgroup$
    – Roman
    Commented Dec 26, 2020 at 14:29
  • $\begingroup$ @Roman Good lead, thanks! I seem to remember this from a livestream. This feature may not be ready for primetime? $\endgroup$
    – Chris K
    Commented Dec 26, 2020 at 14:54
  • $\begingroup$ On my Mac, I get the same results as what you show for v12.1, with either v12.1.1 or v12.2 $\endgroup$
    – Bob Hanlon
    Commented Dec 26, 2020 at 15:04
  • $\begingroup$ @BobHanlon Strange! I added by $Version info. $\endgroup$
    – Chris K
    Commented Dec 26, 2020 at 15:34
  • $\begingroup$ I am using v12.2 on a MacBookPro with macOS 11.1 $\endgroup$
    – Bob Hanlon
    Commented Dec 26, 2020 at 15:39

2 Answers 2

10
$\begingroup$

I think this is (seen by WRI as) an improvement, and the change is marked in the docs for Solve (noted in the comments). In the docs, it is also indicated how Assumptions are used:

So really, it just amounts to some syntactic sugar.

On V12.0 and V12.1,

Solve[n == n E^(r (1 - n)) && n >= 0, {n}]

gives a set of three solutions equivalent to the V12.2 result in the OP with $Assumptions = {n >= 0}. In V12.0, the second solution of the three is simply {n -> 1}, but Simplify@Solve[...] makes the results in all three versions identical.

In short, the new use of $Assumptions/Assumptions does not seem to represent any major change in how solutions are computed. I suppose what is more worrying is that code that uses $Assumptions and Solve and further assumes Solve does not use $Assumptions might break. Might have to write Block[{$Assumptions = True}, Solve[...]] around all my instances of Solve now.

$\endgroup$
1
  • 3
    $\begingroup$ Better to cut that extra sugar from the diet, especially when the results are a questionable improvement over the old version -- having to add an extra Simplify just to get back to where we were before in my first example or missing the solution n1==0 when n2==2 in my second example. $\endgroup$
    – Chris K
    Commented Dec 28, 2020 at 1:40
4
$\begingroup$

FWIW, the fact that Solve did not accept Assumptions was a common complaint. To paraphrase a famous U.S. president, you can't please all of the people all of the time...

Over time, we have added Assumptions as a option to more and more functions. E.g, DSolve didn't used to have it, but now it does (for several versions). One of the risks of using $Assumptions instead of passing it in manually is precisely that some function may unexpectedly change in behavior. That is one reason I prefer to passing assumptions to each call except in certain very targeted contexts. YMMV.

$\endgroup$
1
  • 1
    $\begingroup$ Makes sense. I suppose my real issue is that adding assumptions leads to what I'd consider worse answers (I don't want to see things like ConditionalExpression[1, Re[r] == 0 || Re[r] > 0 || Re[r] < 0]). Turns out that was always there, I just never encountered it until $Assumptions became used automatically. $\endgroup$
    – Chris K
    Commented Jan 20, 2021 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.