3
$\begingroup$

I'm trying to compute the limit $\lim_{x\rightarrow \infty}a^x$ for $a>0$ in Mathematica and I would want it to give me the conditional solutions depending on the value of the paramter $a$. However, when I input

Limit[a^x, x -> ∞, Assumptions -> a > 0, 
 GenerateConditions -> True]

the output is

ConditionalExpression[∞, Log[a] > 0]

That is, it is only considering the case when $a>1$, but not the cases when $0<a<1$ or $a=1$, which should yield $0$ and $1$, respectively. I've tried to look at the documentation pages, but the only option that I have found related to conditions for the parameters is GenerateConditions->True, but it doesn't work with that.

$\endgroup$
2
  • 2
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Oct 7, 2021 at 14:00
  • 2
    $\begingroup$ Some functions will (according to the documentation for GenerateConditions) accept an option of the form GenerateConditions->All which will return a result for all possible cases using Piecewise. This seems like the sort of behavior you're looking for. However, the documentation also says that some functions don't support all of the listed options, and trying to use this option in Limit returns an error, so I suspect that this feature is not implemented for Limit. $\endgroup$ Oct 7, 2021 at 17:09

2 Answers 2

4
$\begingroup$

No one asked for a workaround, so maybe the bad news that Limit does not do what the OP wants is enough. But here's a workaround:

repl = {dom_ /; ! TrueQ@Not@dom :> (
     Limit[a^x, x -> \[Infinity],
      Assumptions -> dom, GenerateConditions -> True] /. {
       ConditionalExpression[r1_, d1_] :> (
         Sow[{r1, Reduce[dom && d1]}];
         Reduce[dom && Not[d1]]), (* subtract the condition d1 from the domain *)
       _Limit :> (
         Sow[{Undefined, True}];
         False),                  (* no solution: we're done *)
       r1_ :> (
         Sow[{r1, dom}];
         False)                   (* unconditional solution: we're done *)
       }
     )
   };

a > 0 //  (* starting domain *)
    (Sow[{Undefined, ! #}]; #) & // (* optional *)
   ReplaceRepeated@repl // Reap //
 Replace@{{_, {pw_}} :> Piecewise[pw]}
(*
ConditionalExpression[
 Piecewise[{
   {Infinity, a > 1},
   {0, 0 < a < 1},
   {1, a == 1}}, 0],
 a > 0]
*)

Removing the optional line yields just the piecewise expression.

I've said elsewhere that Assumptions are logically distinct from constraints ($A \Rightarrow X$ versus $A \wedge X$, respectively), though often the distinction is hard to see in the computed results, because a solution that satisfies $A \wedge X$ automatically satisfies $A \Rightarrow X$. It may be in some cases, the above won't work with Limit; however it works in the case at hand.

$\endgroup$
2
  • 2
    $\begingroup$ Should be 1 for a==1. $\endgroup$
    – Carl Woll
    Oct 7, 2021 at 18:27
  • 3
    $\begingroup$ @CarlWoll Oops, I got interrupted and copied the wrong code (without GenerateConditions). Thanks, $\endgroup$
    – Michael E2
    Oct 8, 2021 at 3:42
2
$\begingroup$

Here's a piece of code that might work. It definitely works for this case; who knows how well it will work for others. Basically, recurselimit runs Limit on your expression (with GenerateConditions -> True) and checks to see if a ConditionalExpression was generated. If it was, it runs Limit again with Not[condition] appended to your list of original assumptions. If the result of Limit was not a ConditionalExpression, the limit is true regardless of the remaining assumptions, and we exit the recursion. At each stage, the value of the limit and the conditions attached to it are seeded using Sow, and then the Reap at the end collects them and puts them into a Piecewise function.

This was my first time seriously using Sow and Reap in Mathematica, so there are probably more elegant ways of doing what I've done here. Still, it was fun.

recurselimit[expr_, limit_Rule, Assumptions -> assum_, ___] :=
 (partiallimit = Limit[expr, limit, Assumptions -> assum, GenerateConditions -> True];
   If[!(Head[partiallimit] === ConditionalExpression),
     Sow[{partiallimit, Reduce[assum]}],
     Sow[{partiallimit[[1]], Reduce[assum && partiallimit[[2]]]}]; 
     recurselimit[expr, limit, Assumptions -> And[assum, ! partiallimit[[2]]]]]
  )
Reap[recurselimit[a^x, x -> \[Infinity], Assumptions -> a > 0]];
Piecewise[First[%[[2]]],Null]

enter image description here

$\endgroup$
4
  • $\begingroup$ Probably something like Piecewise[{{Infinity, a>1}, {1, a==1}}, 0] would be better because the assumption a>0 means the Null case can't happen? $\endgroup$
    – Carl Woll
    Oct 7, 2021 at 18:29
  • $\begingroup$ @CarlWoll: I was thinking of the case where someone later supplies an argument 'a' that didn't satisfy the original assumptions. I thought about having it default to 'Indeterminate' or 'Undefined' instead, but the former isn't strictly true either and the latter gave me some weird output that I thought would be confusing. $\endgroup$ Oct 7, 2021 at 19:46
  • $\begingroup$ Should Simplify[Piecewise[{{Infinity, a > 1}, {1, a == 1}, {0, a > 0}}, Null], a > 0] return Piecewise[{{Infinity, a > 1}, {1, a == 1}, {0, a > 0}}, Null] or Piecewise[{{1, a == 1}, {Infinity, a > 1}}, 0]? By your logic, you would return the first version, while Mathematica returns the second. So, I would say, returning a version with Null does not follow the Mathematica paradigm. $\endgroup$
    – Carl Woll
    Oct 7, 2021 at 19:55
  • $\begingroup$ Also, with: Reap[recurselimit[a^x, x -> \[Infinity], Assumptions -> a >= 1]] you get an incorrect answer, since the 0 < a < 1 case now returns Null. $\endgroup$
    – Carl Woll
    Oct 7, 2021 at 20:38

Your Answer

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

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