Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
    • Constraint Solving Order Puzzles
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
    • solve...before Bias Puzzles
      • Classic a->b Bias Shift
      • Three-Branch Kind Selection
      • Reverse Bias with solve b before a
      • m<n Cardinality Bias
      • Mode Branch Collapse Under Extra Relation
      • Three-Variable solve-before Chain
    • randomize() with Puzzles
    • Randomization & Constraint Puzzles: Tricky Q&A
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←solve...before Bias Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. solve...before Bias Puzzles
  5. Reverse Bias with solve b before a
On this page

    VLSI DV Interview PuzzlesAll levels

    Reverse Bias with solve b before a

    What is P(a==1) by tuple counting, and what exact value does solve b before a give?

    Puzzle

    Difficulty: Easy · Puzzle 3 of 6 · Topic: solve...before Bias Puzzles

    What is P(a==1) by tuple counting, and what exact value does solve b before a give?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    class sb_reverse;
      rand bit a;
      rand bit [1:0] b;
      constraint c_rel { (a == 0) -> (b == 0); }
      // Variant: solve b before a;
    endclass

    Hint

    With b first, b is uniform over 4 values; only b==0 leaves a free.

    Step-by-step solution

    Diagram
    1) Legal tuples are (a=0,b=0) plus (a=1,b=0..3) -> total 5 tuples.
    2) Tuple baseline gives P(a==1)=4/5.
    3) With solve b before a, b is chosen first, uniformly over its 4 feasible values (all have a legal completion).
    4) For b!=0 (probability 3/4), a must be 1; for b=0 (probability 1/4) both a values are legal, 1/2 each.
    5) P(a==1) = 3/4 + (1/4)*(1/2) = 7/8. The 5 legal tuples are unchanged.

    Answer

    Answer: Baseline P(a==1)=4/5; with `solve b before a` it is exactly 7/8 (the legal set stays at 5 tuples).

    How this was checked

    Checked by running a model of the rule in a Python model. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). Same 5 tuples; the three orderings give 4/5, 7/8 and 1/2.

    Why candidates get it wrong

    Reversing the order matters: the same legal set gives 4/5 with no ordering, 7/8 with b first, and 1/2 with `solve a before b`. Verilator 5.048 ignores solve-before and returned P(a==1)=1.0 for this class in a 300-sample run, so the exact fraction comes from the LRM rule, not from a simulation.

    Interviewer follow-up

    Which explicit dist on a would neutralize this order-induced skew? Model answer: `a dist {0 := 1, 1 := 1};`. Only if you also remove `solve b before a`: with it still in the class, b is chosen uniformly first and a is forced to 1 whenever b!=0, so P(a==1) stays 7/8 whatever weights a has (dist can only weight values that remain feasible). Without the solve-before, `a dist {0:=1, 1:=1}` gives 1/2 under the marginal reading (tool-dependent). The LRM-defined way is to swap the order to `solve a before b;`, which gives 1/2 exactly.

    Say it out loud

    There are five legal tuples, a zero with b zero and a one with b zero to three, so by counting the probability that a is one is four fifths. With solve b before a, b is chosen first, uniformly over its four feasible values: for b not zero, a must be one, and for b zero it is half each, so the answer is three quarters plus one eighth, seven eighths. The trap is that the order matters: the same legal set gives four fifths, seven eighths, or one half with solve a before b. Next I would put the solve-before on the variable whose balance I actually want.

    Related topics

    • Implication, if/else and solve...before

    • The Solution-Space Mental Model

    • Back to solve...before Bias Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    100 / 293

    Next: m<n Cardinality Bias

    Up next

    Up nextm<n Cardinality Bias

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Classic a->b Bias Shift
    • Mode Branch Collapse Under Extra Relation
    • Three-Variable solve-before Chain