4
$\begingroup$

I want that Mathematica assumes every symbol like Subscript[s,i] to be evaluate as a real and positive number. I have tried

$Assumptions = {Element[{h, k}, Integers], h > -1, k > -1, 
  Element[{Subscript[m, _], Subscript[s, _]}, Reals], Subscript[s, _] > 0}

but

Subscript[g, i_][x_] := 
  1/√(2 π Subscript[s, i]) Exp[-((x - Subscript[m, i])^2/(2 Subscript[s, i]))];

Simplify@Integrate[Subscript[g, i][x] Subscript[g, j][x], {x, -∞, ∞}]

still gives conditional expression for the integrand. Any suggestion? Thanks!

$\endgroup$

2 Answers 2

4
$\begingroup$

Patterned assumptions seem to need to match the ConditionalExpression's condition exactly to work out for some cases.

The ∈ Reals-assumptions do work as you gave them, while the inequality Subscript[s,_]>0 does not, but observe the different behavior of Subscript[s,_]>=0:

Evaluating without any assumptions first:

f = 1/√(2 π Subscript[s, 
   i]) Exp[-((x - Subscript[m, i])^2/(2 Subscript[s, i]))]
expr=Integrate[f, {x, -∞, ∞}]
(* ConditionalExpression[1, Re[Subscript[s, i]] >= 0] *) 

(Note, that the assumptions about h, k and m have no effect and are therefore superfluous.)

Now, bringing in the patterned assumptions in two versions:

greaterOnly = And @@ {Subscript[s, _] > 0, Element[Subscript[s, _], Reals]}
greaterEqual = And @@ {Subscript[s, _] >= 0, Element[Subscript[s, _], Reals]}

Refine[expr,greaterOnly]
(* ConditionalExpression[1, Subscript[s, i] >= 0] *) 
Refine[expr,greaterEqual]
(* 1 *)

So, the Element-part of assumptions is used in any case, while the inequality requires a "perfect" match.

Hope this helped!

Note: The behavior seems to depend on the Mathematica version. The code above works in 10.1, but behaves differently in 9.x and 8.x (see comments).

$\endgroup$
2
  • $\begingroup$ Which version are you using? In v9.0.1, both of the assumptions failed. And in v8.0.4, the result is on the contrary! $\endgroup$
    – xzczd
    Apr 13, 2015 at 8:03
  • $\begingroup$ @xzczd: I am using 10.1. $\endgroup$
    – Jinxed
    Apr 13, 2015 at 8:07
1
$\begingroup$

The document never promises that pattern-matching is supported inside Assumptions. (Though in some cases it does seem to be!) So the only stable way I can think of is as following:

$Assumptions = {};(*This is to guarentee the Join below will work*)
Subscript[g, i_][x_] := 
    ($Assumptions = Union[$Assumptions~Join~
     {{Subscript[m, i], Subscript[s, i]} ∈ Reals, Subscript[s, i] > 0}]; 
   Exp[-((x - Subscript[m, i])^2/(2 Subscript[s, i]))]/Sqrt[2 π Subscript[s, i]]);

Simplify[Integrate[Subscript[g, i][x] Subscript[g, j][x], {x, -∞, ∞}]]

Tested in v9.0.1 and v12.3.1, Windows 10.

$\endgroup$
6
  • $\begingroup$ This still gives a conditional expression in Mathematica 9. $\endgroup$
    – Fabio
    Apr 13, 2015 at 12:14
  • $\begingroup$ @Fabio Well, the above code has been tested in v9.0.1, vista 32bit. Have you tried it with a fresh kernel? $\endgroup$
    – xzczd
    Apr 13, 2015 at 12:25
  • $\begingroup$ Yes, I have tried. I'm running Linux 64bit. Apparently, Mathematica behaves differently! $\endgroup$
    – Fabio
    Apr 14, 2015 at 17:13
  • $\begingroup$ @Fabio Just encountered another example showing pattern-matching should be avoided in Assumption: mathematica.stackexchange.com/a/273665/1871 $\endgroup$
    – xzczd
    Sep 19, 2022 at 13:32
  • 1
    $\begingroup$ That being said: Wolfram should strive to make it work reliably, as Patterns are such an ubiquitous feature of the Wolfram language, that it is hard to argument, why Mathematica is so very picky about its usage with assumptions $\endgroup$
    – Jinxed
    Oct 24, 2022 at 18:04

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.