Difficulty: Medium · Puzzle 4 of 6 · Topic: Distribution Puzzles (`dist`, `:=` vs `:/`)
After intersecting c_dist with c_clip, compute P(x==3) and P(x==6).
class pruned_dist;
rand int unsigned x;
constraint c_dist {
x dist { [0:4] := 1, [5:9] := 3 };
}
constraint c_clip { x inside {[3:7]}; }
endclassRemove disallowed values first, then renormalize surviving weights.
1) Base per-value weights: 0..4 ->1 each, 5..9 ->3 each.
2) c_clip keeps only values 3,4,5,6,7 with weights 1,1,3,3,3.
3) Total surviving weight = 11.
4) P(3)=1/11.
5) P(6)=3/11.Answer: P(x==3)=1/11 (~9.09%) and P(x==6)=3/11 (~27.27%).
Checked by running a model of the rule in a Python model and Verilator 5. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). Removes the values the hard constraint excludes, then renormalizes the surviving dist weights. Verilator 5.048 legality only: dist plus the hard clip solves and x stays in 3..7.
The original total is 5*1 + 5*3 = 20, and dividing by 20 would give 1/20 and 3/20, which do not sum to 1 over the legal values. A dist weight is relative to the values that survive the hard constraints, so the denominator is the surviving 11.
What if c_clip changes to x inside {[0:4]} only? Model answer: only the weight-1 values survive, so the five values 0..4 are uniform at 1/5 each; P(x==3)=1/5 and P(x==6)=0. The weight-3 clause contributes nothing once all of [5:9] is clipped.
The hard constraint keeps only values three to seven, with weights one, one, three, three, three, so the surviving weight is eleven. The probability that x is three is one eleventh and that x is six is three elevenths. The trap is dividing by the original total of twenty; dist weights are relative to the values that survive the hard constraints. Next I would check whether any weighted range is clipped away completely.