Skip to content

LazyMath mm_dPr Library

Discrete probability distribution routines for binomial statistics, minimum trial solver, and interactive binomial sampling.

For full asymptotic time/space proofs and benchmarks across the mm_* library, see the Algorithm & Complexity Report.

mm_dPr\samplebinom(n, p)

  • n: Number of independent trials \(n\)
  • p: Success probability per trial \(p\)

Exam question example:

Interactive Binomial Simulation Prompt Demonstration

Simulate a binomial experiment with $n = 400$ and $p = 0.4$. When $n > 10$, an on-screen dialog automatically asks whether to render the full discrete table, avoiding CAS slowdown.

CAS Output:

1.1 *Doc1
mm_dPr\samplebinom$\left(400, 0.4\right)$

$\text{Table Prompt (} n > 10 \text{): Print table? [No } \implies \text{Instant Summary]}$
$$\text{Sample Binomial: } \mu = 160, \quad \sigma^2 = 96, \quad \sigma = 9.7980$$
Done

mm_dPr\binominfo(n, p)

  • n: Number of independent trials \(n\)
  • p: Success probability per trial \(p\)

Exam question example:

2022 VCAA Exam 2 Section B Question 3a 2 marks

Let $X \sim \text{Bi}(20, 0.28)$. Find the mean $E(X)$, variance $\text{Var}(X)$, standard deviation $\text{sd}(X)$, and standard deviation of $\hat{p}$.

CAS Output:

1.1 *Doc1
mm_dPr\binominfo$\left(20, 0.28\right)$

$E(X) = 20(0.28) = 5.6 \left(\frac{28}{5}\right), \quad \text{Var}(X) = 20(0.28)(0.72) = 4.032 \left(\frac{504}{125}\right)$
$$E(X) = 5.6000, \quad \text{Var}(X) = 4.0320, \quad \text{sd}(X) = 2.0080, \quad \text{sd}(\hat{p}) = 0.1004$$
Done

mm_dPr\binomsolve(n, p, thres, mode)

  • n: Known trials (or parameter string "n")
  • p: Known success probability (or parameter string "p")
  • thres: Probability target threshold
  • mode: Inequality condition e.g. ">=" or "<="

Complexity Refactoring: Analytical Logarithmic Jump \(\mathcal{O}(N_{\text{trials}}) \to \mathcal{O}(1)\)

  • Time Complexity: \(\mathcal{O}(N_{\text{trials}}) \to \mathcal{O}(1)\) direct logarithmic jump + \(\le 2\) boundary checks.
  • Space Complexity: \(\mathcal{O}(N_{\text{trials}}) \to \mathcal{O}(1)\) auxiliary space.
  • Optimization: Replaces the sequential While binomCdf(...) < target loop with the exact logarithmic lower-bound initialization \(n_0 = \left\lfloor \frac{\ln(1-T)}{\ln(1-p)} \right\rfloor\), executing in 144.8 ms.

Exam question example:

2024 VCAA NHT Exam 2 Section B Question 3d 2 marks

Find the smallest integer $n$ such that $\Pr(X \ge 1) \ge 0.95$ when $p = 0.08$.

CAS Output:

1.1 *Doc1
mm_dPr\binomsolve$\left(\text{"n"}, 0.08, 0.95, \text{">="}\right)$

$\text{Condition: } 1 - (1 - 0.08)^n \ge 0.95 \implies n \ge \frac{\ln(0.05)}{\ln(0.92)} = 35.92$
$$\text{Min } n = 36$$
Done