Verifying probabilities equality by imposing conditions

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.

• What should P(z1+z2==2,z1==1,z2==1) mean? Jan 8 at 14:17
• Hello @DanielHuber the commas mean intersections Jan 8 at 14:37
• But in this case P(z1+z2==2,z1==1,z2==1) is a tautology, z1==1&& z2==1 imply z1+z2==2 Jan 8 at 14:43
• @DanielHuber yes, is it possible to simplify the left term in Mathematica? The simplified one should be the right term Jan 8 at 14:45
• 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] Jan 8 at 14:55

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} *)
• Hello @MarcoB thank you very much for your helpful code. Jan 8 at 18:41
• How did you specify the independence of the random variables? Jan 8 at 20:05
• @Gennaro They should be independent by default here. I think you'd have to work harder to indicate if they are somehow correlated. Jan 8 at 20:09
• if possible can you post the documentation where I can find this implicit hypothesis please? Jan 8 at 20:39
• I found it here reference.wolfram.com/language/ref/Probability.html Jan 8 at 20:57

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, #[] + #[] == 2 && #[] == 1 && #[] == 1 &]
(* {{1, 1, 2}} *)

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

So the probabilities are both 1/16:

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