2
$\begingroup$

I'd like to verify the following equality in Mathematica:

$$ P(Z_1+Z_2=2,Z_1=1,Z_2=1)=P(Z_1=1,Z_2=1) $$

by knowing that $Z_1,Z_2 \in \lbrace 1,2,3,4 \rbrace$ are two independent and uniform random variables.

$\endgroup$
9
  • $\begingroup$ What should P(z1+z2==2,z1==1,z2==1) mean? $\endgroup$ Jan 8 at 14:17
  • $\begingroup$ Hello @DanielHuber the commas mean intersections $\endgroup$ Jan 8 at 14:37
  • 1
    $\begingroup$ But in this case P(z1+z2==2,z1==1,z2==1) is a tautology, z1==1&& z2==1 imply z1+z2==2 $\endgroup$ Jan 8 at 14:43
  • $\begingroup$ @DanielHuber yes, is it possible to simplify the left term in Mathematica? The simplified one should be the right term $\endgroup$ Jan 8 at 14:45
  • $\begingroup$ You may e.g. write your equations by zeros of polynomials and use Groebner Basis like: GroebnerBasis[{z1 + z2 - 2, z1 - 1, z2 - 1}, {z1, z2}] Or you introduce a third variable and eliminate it like: Eliminate[{z == z1 + z2 - 2, z1 == 1, z2 == 1}, z] $\endgroup$ Jan 8 at 14:55
5
$\begingroup$

The code below calculates the two probabilities and allows you to verify that they are the same by inspection.

Probability[
 {z1 == 1 && z2 == 1, z1 == 1 && z2 == 1 && z1 + z2 == 2},
 {
  Distributed[z1, DiscreteUniformDistribution[{1, 4}]],
  Distributed[z2, DiscreteUniformDistribution[{1, 4}]]
 }
]

(*Out: {1/16, 1/16} *)
$\endgroup$
5
  • $\begingroup$ Hello @MarcoB thank you very much for your helpful code. $\endgroup$ Jan 8 at 18:41
  • $\begingroup$ How did you specify the independence of the random variables? $\endgroup$ Jan 8 at 20:05
  • $\begingroup$ @Gennaro They should be independent by default here. I think you'd have to work harder to indicate if they are somehow correlated. $\endgroup$
    – MarcoB
    Jan 8 at 20:09
  • $\begingroup$ if possible can you post the documentation where I can find this implicit hypothesis please? $\endgroup$ Jan 8 at 20:39
  • $\begingroup$ I found it here reference.wolfram.com/language/ref/Probability.html $\endgroup$ Jan 8 at 20:57
5
$\begingroup$

The answer by @MarcoB is almost always the way to go. But if the set of equations ( {z1 == 1 && z2 == 1, z1 == 1 && z2 == 1 && z1 + z2 == 2}) is complicated enough such that Probability doesn't work, you might try a brute force method.

This approach simply creates the sample space of equally likely outcomes and then selects the outcomes that satisfies each condition.

sampleSpace = Flatten[Table[{z1, z2, z1 + z1}, {z1, 1, 4}, {z2, 1, 4}], 1]
(* {{1, 1, 2}, {1, 2, 2}, {1, 3, 2}, {1, 4, 2}, {2, 1, 4}, {2, 2, 4}, 
    {2, 3, 4}, {2, 4, 4}, {3, 1, 6}, {3, 2, 6}, {3, 3, 6}, {3, 4, 6},
    {4, 1, 8}, {4, 2, 8}, {4, 3, 8}, {4, 4, 8}} *)

subset1 = Select[sampleSpace, #[[1]] + #[[2]] == 2 && #[[1]] == 1 && #[[2]] == 1 &]
(* {{1, 1, 2}} *)

subset2 = Select[sampleSpace, #[[1]] == 1 && #[[2]] == 1 &]
(* {{1, 1, 2}} *)

So the probabilities are both 1/16:

Length[subset1]/Length[sampleSpace]
(* 1/16 *)
Length[subset2]/Length[sampleSpace]
(* 1/16 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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