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.
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} *)
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 *)
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$