I apologize if it is a too elementary question but I could not find the appropriate documentation so far.
My goal is simple. I would like to add some assumptions that are defined in terms of patterns rather than symbols. For example, I would like to something like this
$Assumptions = { a[ ___ ] > 0 };
In my ideal world, this should set every expression with the Head
a
should be considered positive. Is it possible in Mathematica?
EDIT: Thanks. Following the first comment and the first answer, I did the following experiment. I still got puzzled about the result. Maybe it is just because of the intricate interaction between Integrate
and $Assumptions
.
$Assumptions = {A[___] > 0, B > 0};
Integrate[ Exp[ - A[x] t] , {t, 0, \[Infinity]}]
Integrate[ Exp[ - B t] , {t, 0, \[Infinity]}]
(* output *)
ConditionalExpression[1/A[x], Re[A[x]] > 0]
1/B
In this example, Integrate
does not make use of the fact A[___]>0
.
Answer
This is correct; you can also use the following forms, which are generally considered better suited to functional-programming style (in that you don't change the variables globally, just locally):
Block[
{$Assumptions = (a[___] > 0)},
code]
or, better yet,
Assuming[
a[___] > 0,
code]
Edit:
(In respond to the OP's code sample) I'm a bit surprised that the code treats A[x] and B differently, but the problem seems to come from an assumption that A[x] could be a complex number. This can be fixed with an additional assumption (also pointed out by march):
Assuming[
{A[___] > 0, B > 0, A[___] \[Element] Reals},
{Integrate[Exp[-A[x] t], {t, 0, \[Infinity]}],
Integrate[Exp[-B t], {t, 0, \[Infinity]}]}]
{1/A[x], 1/B}
I would be interested to hear if anyone else knows why A[x] and B are treated differently by the integration system. I initially thought it might be the assumption that x is a variable, but this example is slightly more illustrative:
Assuming[
{c[___] > 0, c[x] > 0, f > 0},
{Integrate[Exp[-c[1]*t], {t, 0, \[Infinity]}],
Integrate[Exp[-c[x]*t], {t, 0, \[Infinity]}],
Integrate[Exp[-f*t], {t, 0, \[Infinity]}]}]
{ConditionalExpression[1/c[1], Re[c[1]] > 0], 1/c[x], 1/f}
It seems to me that assumptions containing patterns are treated differently than explicit assumptions, yet it is clear from my previous example (with A[___] \[Element] Reals
) that assumptions with patterns are not just being ignored.
Comments
Post a Comment