11

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Sungmin
  • 2,285
  • 15
  • 23
  • It looks to me like it works. Starting from a fresh kernel, I executed $Assumptions = {a[__] > 0};Refine[a[3] > 0], and the result was True. You should have just tried it! :) (As "simple" as this is, I never thought of it.) – march Sep 18 '15 at 21:38
  • @march Thanks. Indeed your example works. Can you comment on my experiment added now? – Sungmin Sep 18 '15 at 21:47
  • Well, Integrate assumes that its argument (and all variables) are all complex. It seems like $Assumptions is very conservative, in the sense that it will only apply the A[___] >0 assumption if it knows it's real. if it knows A[___] is real. Add Element[A[___], Reals] to $Assumptions, and you don't get the conditional expression. I'm not sure about the differences between those two, though. That's interesting. – march Sep 18 '15 at 21:50
  • @march Your suggestion fixed the problem. Thank you. – Sungmin Sep 18 '15 at 21:54
  • Don't use uppercase initials on your symbols... that's just asking for trouble. – ciao Sep 18 '15 at 22:08
  • @ciao Thanks for you advice. – Sungmin Sep 18 '15 at 22:14

1 Answers1

8

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.

nben
  • 2,148
  • 9
  • 20