Question 1

(ns assignments.hw2.q1
  (:require
    [assignments.hw2.utils :refer :all]
    [scicloj.kindly.v4.kind :as kind]))

1) Find \(P(A ∩ B)\) if \(P(A) = 0.2\), \(P(B) = 0.4\) and \(P(A|B) + 0.5P(A^c|B) = 0.75\).

Given:

\[P(A) = 0.2, P(B) = 0.4, P(A|B) + 0.5P(A^c|B) = 0.75\]

  1. Solve P(A|B):

\[P(A|B) + 0.5(1 - P(A|B)) = 0.75\]

\[P(A|B) + 0.5 - 0.5 P(A|B) = 0.75\]

\[0.5 P(A|B) + 0.5 = 0.75\]

\[0.5 P(A|B) = 0.25\]

\[P(A|B) = 0.5\]

  1. Solve P(A ∩ B):

\[P(A|B) = P(A ∩ B) / P(B)\]

\[P(A ∩ B) = P(A|B) * P(B)\]

\[P(A ∩ B) = 0.5 * 0.4 = 0.2\]

Implementation:

We’ll use linear algebra to solve the system of equations:

\[x + 0.5y = 0.75\]

\[x + y = 1\]

Where \(x = P(A|B)\) and \(y = P(A^c|B)\) and by definition \(P(A|B) + P(A^c|B) = 1\)

This system can be represented in matrix form as:

\[Ax = b\]

Where:

\[A = \begin{bmatrix} 1 & 0.5 \\ 1 & 1 \end{bmatrix}\]

\[x = \begin{bmatrix} P(A|B) \\ P(A^c|B) \end{bmatrix}\]

\[b = \begin{bmatrix} 0.75 \\ 1 \end{bmatrix}\]

We’ll solve this using LU decomposition and forward/backward substitution:

(comment
  (defn p-a-gvn-b [target]
    (let [A (dge 2 2 [1 0.5                                 ; 2x2 Matrix [[1 0.5] [1 1]]
                      1 1]
                 {:layout :row})
          b (dv [target 1])                                 ; Vector [target 1]
          LU (trf! A)                                       ; Perform LU decomposition
          x (mv (tri! LU) b)]                               ; Solve using forward/backward substitution
      ; Return P(A|B)
      (first x))))
(let [target 0.75 p-a-given-b (p-a-gvn-b target)]
  (kind/tex (str "P(A|B) = " p-a-given-b)))

\[P(A|B) = 0.5\]

Answer:

(let [p-a 0.2 p-b 0.4
      p-a-given-b (p-a-gvn-b 0.75)
      p-a-and-b (* p-a-given-b p-b)]
  (answer (str "P(A ∩ B) = " p-a-and-b)))

P(A ∩ B) = 0.2

Interpretation:

  1. When the target is 0.75, we get \(P(A|B) = 0.5\).
  2. The sum \(P(A|B) + P(A^c|B) = 1\) holds true.
  3. The given equation \(P(A|B) + 0.5 P(A^c|B) = 0.75\) is satisfied with the calculated probabilities.

Implications for Probability:

  1. \(P(A|B)\) represents the probability of event A occurring given that B has occurred.
  2. \(P(A^c|B) = 1 - P(A|B)\) is the probability that A does not occur given that B has occurred.
  3. The equation \(P(A|B) + 0.5 P(A^c|B) = 0.75\) combines these conditional probabilities into a weighted sum.

Limitations:

  1. The target value must be between 0.5 and 1 for the probabilities to make sense.
  2. This method assumes that all events and probabilities are valid within the context of probability theory.

Explanation:

We solved for \(P(A|B)\) using the given equation and found it to be 0.5. Then, we calculated \(P(A ∩ B)\) using the formula \(P(A ∩ B) = P(A|B) * P(B)\).

Verification:

  • Check the Given Equation:

\[P(A|B) + 0.5 P(A^c|B) = 0.5 + 0.5 * 0.5 = 0.75\]

  • Check the Sum of Probabilities:

\[P(A|B) + P(A^c|B) = 0.5 + 0.5 = 1\]

Note on Implementation:

We used a simple linear system solver to find \(P(A|B)\). The linear algebra approach illustrates how systems of equations can be solved using matrices, even for basic probability problems.

Conclusion:

The solution correctly finds \(P(A ∩ B) = 0.2\) by first determining \(P(A|B) = 0.5\) and then applying the definition of conditional probability.

source: src/assignments/hw2/q1.clj